Skip to content

bpo-32591: fix abort in _PyErr_WarnUnawaitedCoroutine during shutdown #5337

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

Merged
merged 1 commit into from
Jan 26, 2018

Conversation

njsmith
Copy link
Contributor

@njsmith njsmith commented Jan 26, 2018

When an unawaited coroutine is collected very late in shutdown --
like, during the final GC at the end of PyImport_Cleanup -- then it
was triggering an interpreter abort, because we'd try to look up the
"warnings" module and not only was it missing (we were prepared for
that), but the entire module system was missing (which we were not
prepared for).

I've tried to fix this at the source, by making the utility function
get_warnings_attr robust against this in general. Note that it already
has the convention that it can return NULL without setting an error,
which is how it signals that the attribute it was asked to fetch is
missing, and that all callers already check for NULL returns.

There's a similar check for being late in shutdown at the top of
warn_explicit, which might be unnecessary after this fix, but I'm not
sure so I'm going to leave it.

https://bugs.python.org/issue32591

When an unawaited coroutine is collected very late in shutdown --
like, during the final GC at the end of PyImport_Cleanup -- then it
was triggering an interpreter abort, because we'd try to look up the
"warnings" module and not only was it missing (we were prepared for
that), but the entire module system was missing (which we were not
prepared for).

I've tried to fix this at the source, by making the utility function
get_warnings_attr robust against this in general. Note that it already
has the convention that it can return NULL without setting an error,
which is how it signals that the attribute it was asked to fetch is
missing, and that all callers already check for NULL returns.

There's a similar check for being late in shutdown at the top of
warn_explicit, which might be unnecessary after this fix, but I'm not
sure so I'm going to leave it.
@1st1 1st1 merged commit dba976b into python:master Jan 26, 2018
@bedevere-bot
Copy link

@njsmith: Please replace # with GH- in the commit message next time. Thanks!

@Mariatta
Copy link
Member

Ok that should have been addressed to @1st1 who merged the commit..

@python python deleted a comment from bedevere-bot Jan 26, 2018
@bedevere-bot
Copy link

@1st1: Please replace # with GH- in the commit message next time. Thanks!

@Mariatta
Copy link
Member

Yay!

@Mariatta
Copy link
Member

(sorry for the noise)

@1st1
Copy link
Member

1st1 commented Jan 26, 2018

@Mariatta sure :)

@njsmith njsmith deleted the bpo-32591-fix-late-shutdown-warning branch January 27, 2018 00:14
@Yhg1s
Copy link
Member

Yhg1s commented Apr 19, 2018

This also fixes bpo-26153, so it should be backported. Unfortunately the test doesn't trigger the problem on 3.6, presumably because the underlying coroutine changes aren't in 3.6, and as mentioned in bpo-26153 I haven't been able to find a good reproducer for the crash, so I'll backport the code change but not the test for now.

@miss-islington
Copy link
Contributor

Thanks @njsmith for the PR, and @1st1 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @njsmith and @1st1, I could not cleanly backport this to 3.6 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker dba976b8a28d6e5daa66ef31a6a7c694a9193f6a 3.6

Yhg1s pushed a commit to Yhg1s/cpython that referenced this pull request Apr 19, 2018
…utdown (pythonGH-5337)

When an unawaited coroutine is collected very late in shutdown --
like, during the final GC at the end of PyImport_Cleanup -- then it
was triggering an interpreter abort, because we'd try to look up the
"warnings" module and not only was it missing (we were prepared for
that), but the entire module system was missing (which we were not
prepared for).

I've tried to fix this at the source, by making the utility function
get_warnings_attr robust against this in general. Note that it already
has the convention that it can return NULL without setting an error,
which is how it signals that the attribute it was asked to fetch is
missing, and that all callers already check for NULL returns.

There's a similar check for being late in shutdown at the top of
warn_explicit, which might be unnecessary after this fix, but I'm not
sure so I'm going to leave it..
(cherry picked from commit dba976b)

Co-authored-by: Nathaniel J. Smith <[email protected]>
@bedevere-bot
Copy link

GH-6536 is a backport of this pull request to the 3.6 branch.

Yhg1s added a commit that referenced this pull request May 31, 2018
…utdown (GH-5337) (#6536)

When an unawaited coroutine is collected very late in shutdown --
like, during the final GC at the end of PyImport_Cleanup -- then it
was triggering an interpreter abort, because we'd try to look up the
"warnings" module and not only was it missing (we were prepared for
that), but the entire module system was missing (which we were not
prepared for).

I've tried to fix this at the source, by making the utility function
get_warnings_attr robust against this in general. Note that it already
has the convention that it can return NULL without setting an error,
which is how it signals that the attribute it was asked to fetch is
missing, and that all callers already check for NULL returns.

There's a similar check for being late in shutdown at the top of
warn_explicit, which might be unnecessary after this fix, but I'm not
sure so I'm going to leave it..
(cherry picked from commit dba976b)

Co-authored-by: Nathaniel J. Smith <[email protected]>
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.

7 participants