Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix future issue in sock_connect() #389

Closed
wants to merge 2 commits into from

Conversation

fantix
Copy link
Member

@fantix fantix commented Feb 8, 2021

Seems like, under pressure, more write callbacks may happen before _remove_writer() is called, so we should check for done() instead of cancelled(). I could reproduce this reliably on Linux with @Catstyle's script, and this PR does fix the issue. I tried to hack in a test but it wasn't easy at all (somehow libuv uv_poll_t could fire multiple times in a single event loop, while we're expecting uv_idle_t to step in immediately in the next loop to remove the uv_poll_t)

@fantix fantix marked this pull request as ready for review February 8, 2021 22:14
@fantix fantix requested a review from 1st1 February 8, 2021 22:14
@1st1
Copy link
Member

1st1 commented Feb 8, 2021

Can you see if there are any other sock* apis that check on fut.cancelled and not on fut.done?

CPython fixed the same issue in python/cpython#10419. Seems like under
pressure, more write callbacks may happen before _remove_writer() is
called, so we should check for done().

Fixes MagicStack#378
@fantix fantix force-pushed the t378-fix-sock-connect branch from 1f8fdba to cd85662 Compare February 9, 2021 00:39
@fantix
Copy link
Member Author

fantix commented Feb 9, 2021

Checked again - I think the other sock_* APIs are using the _SyncSocketReader/WriterFuture from #173 which turned out to be a similar issue, therefore they don't have this issue.

Perhaps we should also use _SyncSocketWriteFuture for sock_connect() here? UPDATE: #391

fantix added a commit to fantix/uvloop that referenced this pull request Feb 9, 2021
Use _SyncSocketWriterFuture for cancellation, so that we could remove
the writer directly in the callback.

Fixes MagicStack#378
Closes MagicStack#389
fantix added a commit to fantix/uvloop that referenced this pull request Feb 9, 2021
Use _SyncSocketWriterFuture for cancellation, so that we could remove
the writer directly in the callback.

Fixes MagicStack#378
Closes MagicStack#389
@fantix fantix closed this in #391 Feb 9, 2021
fantix added a commit that referenced this pull request Feb 9, 2021
Use _SyncSocketWriterFuture for cancellation, so that we could remove
the writer directly in the callback.

Fixes #378
Closes #389
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.

event loop loop forever: make lots of sock_connec at the same time
2 participants