Skip to content

fix(aio): handle socket_action errors in _force_timeout - #818

Open
disqualifier wants to merge 1 commit into
lexiforest:mainfrom
disqualifier:fix/force-timeout-socket-action-error
Open

fix(aio): handle socket_action errors in _force_timeout#818
disqualifier wants to merge 1 commit into
lexiforest:mainfrom
disqualifier:fix/force-timeout-socket-action-error

Conversation

@disqualifier

Copy link
Copy Markdown

_force_timeout exists to make sure a missing socket or timer event never
stalls indefinitely. It runs in the background and drives
curl_multi_socket_action every ~100ms, so if a wakeup is ever missed, the
next tick recovers it.

Problem

It calls socket_action() without handling errors, and socket_action()
raises CurlError on a non-OK return. Nothing catches it, so the coroutine
ends. It is never restarted, which leaves the safeguard stopped for the rest
of the session. Nothing recovers a missed wakeup after that, so a request
that only needed the next tick to make progress can stall and hang the caller.

Fix

Handle the error inside _force_timeout. If socket_action() fails, report
it as a CurlCffiWarning and keep the loop running, so the safeguard keeps
doing its job instead of ending on the first error. The request-path calls
that raise CurlError on purpose (add_handle and similar) are left
unchanged.

Test

tests/unittest/test_async.py::test_force_timeout_error injects one failing
socket_action call and checks the safeguard is still running afterward. It
fails on main and passes with this change.

Open question

process_data calls self.socket_action() the same way, outside its own
try, so the same CurlError goes unhandled there too. With _force_timeout
fixed its next tick recovers that socket, so I left it alone to keep this
small. Want the same handling on process_data, or a follow-up?

Checklist

  • I have manually reviewed the changes and fully understand the code.

_force_timeout drives curl_multi_socket_action every ~100ms so a missing
socket or timer event cannot stall a request indefinitely. It called
socket_action() without handling errors, and a non-OK return raises
CurlError. Nothing caught it, so the coroutine ended and was never
restarted, leaving the safeguard stopped for the rest of the session.

Catch the error, report it as a CurlCffiWarning, and keep the loop running.

Co-Authored-By: Zachary Lile <zacklile@hotmail.com>
Signed-off-by: disqualifier <dev@disqualifier.me>
@disqualifier
disqualifier force-pushed the fix/force-timeout-socket-action-error branch from f8bf2f2 to 1545136 Compare August 2, 2026 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant