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

Concurrent drains #1915

Closed
wants to merge 4 commits into from
Closed

Concurrent drains #1915

wants to merge 4 commits into from

Conversation

asvetlov
Copy link
Member

asyncio doesn't support concurrent .drain() calls (#1886 (comment))
This PR proposes a workaround for the issue.

@asvetlov asvetlov mentioned this pull request May 26, 2017
@@ -125,7 +128,18 @@ def drain(self):
yield from w.drain()
"""
if self._protocol.transport is not None:
yield from self._protocol._drain_helper()
if self._is_drain:
fut = asyncio.Future(loop=self._loop)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self._loop.create_future() I guess

self._is_drain = False
if self._drain_waiters:
fut = self._drain_waiters.popleft()
fut.set_result(None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same "deadlock" issue (a,b) can happen here: if future on line 134 is cancelled then other task that
sets result for next waiter will do nothing and all other futures will be in _drain_waiters forever.

a: bugs.python.org/issue27585
b: python/asyncio#393 and propbably python/cpython#1031

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think cancellation tests should be added as well.

@@ -125,7 +128,18 @@ def drain(self):
yield from w.drain()
"""
if self._protocol.transport is not None:
yield from self._protocol._drain_helper()
if self._is_drain:
fut = asyncio.Future(loop=self._loop)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we use same future for all callers?

@asvetlov
Copy link
Member Author

The code is outdated

@asvetlov asvetlov closed this Feb 27, 2018
@asvetlov asvetlov deleted the concurrent-drains branch September 19, 2018 08:57
@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants