-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-95808: Add missing early returns in _asynciomodule.c #95809
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
Conversation
cc @gvanrossum Stumbled upon this while debugging TaskGroups. |
@@ -640,6 +643,9 @@ static void | |||
future_set_cancelled_error(FutureObj *fut) | |||
{ | |||
PyObject *exc = create_cancelled_error(fut); | |||
if (exc == NULL) { | |||
return; | |||
} | |||
PyErr_SetObject(asyncio_CancelledError, exc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the check we're masking the error.
Modules/_asynciomodule.c
Outdated
@@ -631,6 +631,9 @@ create_cancelled_error(FutureObj *fut) | |||
} else { | |||
exc = PyObject_CallOneArg(asyncio_CancelledError, msg); | |||
} | |||
if (exc == NULL) { | |||
return NULL; | |||
} | |||
PyException_SetContext(exc, fut->fut_cancelled_exc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the check we're...segfaulting in PyException_SetContext.
Modules/_asynciomodule.c
Outdated
@@ -631,6 +631,9 @@ create_cancelled_error(FutureObj *fut) | |||
} else { | |||
exc = PyObject_CallOneArg(asyncio_CancelledError, msg); | |||
} | |||
if (exc == NULL) { | |||
return NULL; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PyException_SetContext
steals a reference to its second argument (according to the docs), which implies that the refcount of fut->fut_cancelled_exc
should be adjusted before returning (and also that the Py_CLEAR call below is dodgy).
That said, the call to PyException_SetContext
appears to be a no-op because the block at line 622 is used when that fut_cancelled_exc
is not NULL and that block always returns. That means fut_cancelled_exc
should be NULL if execution gets here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Ronald, you're 100% right. I've pushed an update.
Can you add a test for this? Does monkey patching the |
I think it's hard to add a test for this. I only stumbled upon this because I was modifying the asyncio source. Even if it's possible to add a test for this fringe case, I don't think it's worth the time now, or later when somebody would be reviewing it or running it. |
Thanks @1st1 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11. |
Sorry, @1st1, I could not cleanly backport this to |
GH-96013 is a backport of this pull request to the 3.11 branch. |
@1st1 sorry I don't understand what you mean, I can't unpack this sentence
|
Uh oh!
There was an error while loading. Please reload this page.