Skip to content

fix: tolerate closed curl handles in AsyncCurl cleanup - #807

Open
dokson wants to merge 1 commit into
lexiforest:mainfrom
dokson:fix/async-curl-close-race
Open

fix: tolerate closed curl handles in AsyncCurl cleanup#807
dokson wants to merge 1 commit into
lexiforest:mainfrom
dokson:fix/async-curl-close-race

Conversation

@dokson

@dokson dokson commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #802. Closing a Curl handle while AsyncCurl still tracks it (e.g. add_handle cancelled by a timeout, then curl.close()) left its entries in the internal maps with a nulled pointer, so a later AsyncCurl.close() raised TypeError: initializer for ctype 'void *' must be a cdata pointer, not NoneType.

close() and _pop_future() now skip the C-level removal for already-closed handles, _pop_future() drops the bookkeeping entries even when curl_multi_remove_handle fails (the race in the follow-up comment), and the popped future is cancelled before re-raising so no task is left hanging. Both regression tests fail with the TypeError on current main.

Checklist

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

A Curl handle closed while still tracked by AsyncCurl left its entries
in the internal maps and nulled the underlying pointer, so a later
AsyncCurl.close raised TypeError. Skip the C-level removal for already
closed handles, always drop the bookkeeping entries in _pop_future, and
cancel the pending future when removal fails.
@lexiforest lexiforest added this to the v0.17 milestone Aug 1, 2026
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.

Race condition with AsyncCurl.close

2 participants