http_client: don't arm the websocket timeout after a failed connect #204

Merged
vitalif merged 1 commits from koolkhel/vitastor:http-ws-stray-timer into master 2026-11-29 14:13:58 +03:00
Contributor

Description

Follow-up to #184. start_ws_connection() armed its timer after resolve_and_connect() even when the connection had already failed inside it (connect() refused at once, socket() or TLS setup failing) and its callback had run. Nothing cleared that timer. When it fired, it closed whatever the client was doing then and failed the client's next request with "Websocket connection timed out".

The etcd watcher reaches this path: when a live watch disconnects, its callback opens the next websocket on the same client at once, from inside the failed open.

The timer is now armed only while the connection is in flight, as send_request() does since #184: the client still holds the callback, and no other timer is armed.

Tested: test_http_client now runs its check in three cases: a failed request, a failed request whose callback sends the next one, and a failed websocket open. It also ends the second request early and checks that only the third request's own timeout ends it, which catches a second timer armed for one request. Against current master the websocket case fails; with the fix all three pass. The second case covers the timeout_id < 0 clause from #184, which the old test didn't exercise.

Contributor Name

Yury Luneff (MIND Software LLC, https://mindsw.io)

CLA

### Description Follow-up to #184. `start_ws_connection()` armed its timer after `resolve_and_connect()` even when the connection had already failed inside it (`connect()` refused at once, `socket()` or TLS setup failing) and its callback had run. Nothing cleared that timer. When it fired, it closed whatever the client was doing then and failed the client's next request with "Websocket connection timed out". The etcd watcher reaches this path: when a live watch disconnects, its callback opens the next websocket on the same client at once, from inside the failed open. The timer is now armed only while the connection is in flight, as `send_request()` does since #184: the client still holds the callback, and no other timer is armed. Tested: `test_http_client` now runs its check in three cases: a failed request, a failed request whose callback sends the next one, and a failed websocket open. It also ends the second request early and checks that only the third request's own timeout ends it, which catches a second timer armed for one request. Against current master the websocket case fails; with the fix all three pass. The second case covers the `timeout_id < 0` clause from #184, which the old test didn't exercise. ### Contributor Name Yury Luneff (MIND Software LLC, https://mindsw.io) ### CLA - [x] I accept Vitastor CLA agreement: https://git.yourcmc.ru/vitalif/vitastor/src/branch/master/CLA-en.md
koolkhel added 1 commit 2026-11-29 13:04:09 +03:00
start_ws_connection() armed its timer after resolve_and_connect() even
when the connection had already failed inside it and its callback had
run. Nothing cleared that timer: when it fired, it failed the client's
next request with "Websocket connection timed out". Arm it only while
the connection is in flight, as send_request() does.

Also test the case where the failed request's callback sends the next
request on the same client.
vitalif merged commit 9d695fe690 into master 2026-11-29 14:13:58 +03:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#204
No description provided.