Skip to content

Conversation

@fantix
Copy link
Member

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)

@fantixfantix marked this pull request as ready for review February 8, 2021 22:14
@fantixfantix requested a review from 1st1February 8, 2021 22:14
1st1
1st1 approved these changes Feb 8, 2021
@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(). FixesMagicStack#378
@fantixfantixforce-pushed the t378-fix-sock-connect branch from 1f8fdba to cd85662CompareFebruary 9, 2021 00:39
@fantix
Copy link
MemberAuthor

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. FixesMagicStack#378ClosesMagicStack#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. FixesMagicStack#378ClosesMagicStack#389
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#378Closes#389
Sign up for freeto 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

@fantix@1st1