http_client: don't arm the timeout of a request that has already failed #184
Reference in New Issue
Block a user
No description provided.
Delete Branch "koolkhel/vitastor:http-stray-timer"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
A request can fail inside
http_request():connect()refused at once (ENETUNREACH, EHOSTUNREACH, ablackholeorprohibitroute);socket()failing (EMFILE);In those cases its callback has already run when
send_request()arms the timeout, and the timer was armed anyway. Nothing cleared it: the next request overwrotetimeout_id. Two things could then happen:etcd_call()that also means a switch to the next etcd address. A txn cut off this way may still be applied by etcd after the retry's newer one.etcd_call_oneshot()does, the timer ran on freed memory.The fix arms the timer only while the request is still in flight. Then the client still holds the request's callback and no other timer is armed. A request that failed synchronously has already cleared its callback. A queued request that
next_request()started from that failure has armed its own timer.Tested: new
test_http_client. A request to224.0.0.1:1fails at once with ENETUNREACH. A second request on the same client must then end only by its own 5 s timeout. Without the fix the leftover 1 s timer fails it at 1 s; with the fix the test passes. The use-after-free variant wasn't run under ASan.Contributor Name
Yury Luneff (MIND Software LLC, https://mindsw.io)
CLA