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

gh-92841: Fix asyncio's RuntimeError: Event loop is closed #92842

Merged
merged 2 commits into from
May 17, 2022

Conversation

arhadthedev
Copy link
Member

@arhadthedev arhadthedev commented May 16, 2022

Both asyncio.selector_events._SelectorTransport and asyncio.proactor_events._ProactorBasePipeTransport check if an associated socket is left unclosed and emit a warning on a positive answer.

However, further behavior differs. While _SelectorTransport closes the socket:

def __del__(self, _warn=warnings.warn):
    if self._sock is not None:
        _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
        self._sock.close()

the _ProactorBasePipeTransport attempts to close itself leaving the socked leaked:

def __del__(self, _warn=warnings.warn):
    if self._sock is not None:
        _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
        self.close()

It looks like there was no plan to close the transport itself causing <already closed parent loop>.call_soon().

The deleters were introduced by 978a9af with no explanatory comment about the implementation difference.

Fixes (no autoclose) gh-92841, gh-91233, and gh-83413. Probably fixes (no autoclose) gh-81562.

@arhadthedev
Copy link
Member Author

Note that the NEWS entry uses socket activity instead of pipe activity because _ProactorBasePipeTransport affects sockets via its inheritance chain:

classDiagram
_ProactorBasePipeTransport <|-- _ProactorReadPipeTransport
_ProactorBasePipeTransport <|-- _ProactorBaseWritePipeTransport
_ProactorBasePipeTransport <|-- _ProactorDatagramTransport
_ProactorReadPipeTransport <|-- _ProactorDuplexPipeTransport
_ProactorBaseWritePipeTransport <|-- _ProactorDuplexPipeTransport
_ProactorReadPipeTransport <|-- _ProactorSocketTransport
_ProactorBaseWritePipeTransport <|-- _ProactorSocketTransport

…x107.rst

Co-authored-by: Steve Dower <steve.dower@microsoft.com>
@zooba zooba merged commit 33880b4 into python:main May 17, 2022
@zooba zooba added needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes labels May 17, 2022
@miss-islington
Copy link
Contributor

Thanks @arhadthedev for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Thanks @arhadthedev for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 17, 2022
…honGH-92842)

(cherry picked from commit 33880b4)

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label May 17, 2022
@bedevere-bot
Copy link

GH-92904 is a backport of this pull request to the 3.10 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 17, 2022
…honGH-92842)

(cherry picked from commit 33880b4)

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label May 17, 2022
@bedevere-bot
Copy link

GH-92905 is a backport of this pull request to the 3.11 branch.

miss-islington added a commit that referenced this pull request May 17, 2022
(cherry picked from commit 33880b4)

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
@arhadthedev arhadthedev deleted the asyncio-__del__-runtimeerror branch May 18, 2022 03:35
ambv pushed a commit that referenced this pull request Jun 28, 2022
…GH-92904)

(cherry picked from commit 33880b4)

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants