-
-
Notifications
You must be signed in to change notification settings - Fork 32k
GH-117881: fix athrow().throw()/asend().throw() concurrent access #117882
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
Changes from 7 commits
8418dcc
daf0f35
490e0a9
cbd302d
38b8246
144ddbc
6526f6f
25d8a27
1220aee
d1cedbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
prevent concurrent access to an async generator via athrow().throw() or asend().throw() |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1771,6 +1771,7 @@ async_gen_asend_send(PyAsyncGenASend *o, PyObject *arg) | |||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
if (o->ags_state == AWAITABLE_STATE_INIT) { | ||||||||||||||||||||||||||||||||||
if (o->ags_gen->ag_running_async) { | ||||||||||||||||||||||||||||||||||
o->ags_state = AWAITABLE_STATE_CLOSED; | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was set in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines 2098 to 2113 in 8418dcc
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably could do with a test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test added in 1220aee |
||||||||||||||||||||||||||||||||||
PyErr_SetString( | ||||||||||||||||||||||||||||||||||
PyExc_RuntimeError, | ||||||||||||||||||||||||||||||||||
"anext(): asynchronous generator is already running"); | ||||||||||||||||||||||||||||||||||
|
@@ -1814,10 +1815,24 @@ async_gen_asend_throw(PyAsyncGenASend *o, PyObject *const *args, Py_ssize_t narg | |||||||||||||||||||||||||||||||||
return NULL; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
if (o->ags_state == AWAITABLE_STATE_INIT) { | ||||||||||||||||||||||||||||||||||
if (o->ags_gen->ag_running_async) { | ||||||||||||||||||||||||||||||||||
o->ags_state = AWAITABLE_STATE_CLOSED; | ||||||||||||||||||||||||||||||||||
PyErr_SetString( | ||||||||||||||||||||||||||||||||||
PyExc_RuntimeError, | ||||||||||||||||||||||||||||||||||
"anext(): asynchronous generator is already running"); | ||||||||||||||||||||||||||||||||||
return NULL; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
o->ags_state = AWAITABLE_STATE_ITER; | ||||||||||||||||||||||||||||||||||
graingert marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||
o->ags_gen->ag_running_async = 1; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
result = gen_throw((PyGenObject*)o->ags_gen, args, nargs); | ||||||||||||||||||||||||||||||||||
result = async_gen_unwrap_value(o->ags_gen, result); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
if (result == NULL) { | ||||||||||||||||||||||||||||||||||
o->ags_gen->ag_running_async = 0; | ||||||||||||||||||||||||||||||||||
o->ags_state = AWAITABLE_STATE_CLOSED; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
@@ -2206,10 +2221,31 @@ async_gen_athrow_throw(PyAsyncGenAThrow *o, PyObject *const *args, Py_ssize_t na | |||||||||||||||||||||||||||||||||
return NULL; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
if (o->agt_state == AWAITABLE_STATE_INIT) { | ||||||||||||||||||||||||||||||||||
if (o->agt_gen->ag_running_async) { | ||||||||||||||||||||||||||||||||||
o->agt_state = AWAITABLE_STATE_CLOSED; | ||||||||||||||||||||||||||||||||||
if (o->agt_args == NULL) { | ||||||||||||||||||||||||||||||||||
PyErr_SetString( | ||||||||||||||||||||||||||||||||||
PyExc_RuntimeError, | ||||||||||||||||||||||||||||||||||
"aclose(): asynchronous generator is already running"); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
else { | ||||||||||||||||||||||||||||||||||
PyErr_SetString( | ||||||||||||||||||||||||||||||||||
PyExc_RuntimeError, | ||||||||||||||||||||||||||||||||||
"athrow(): asynchronous generator is already running"); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
return NULL; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
o->agt_state = AWAITABLE_STATE_ITER; | ||||||||||||||||||||||||||||||||||
graingert marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||
o->agt_gen->ag_running_async = 1; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
retval = gen_throw((PyGenObject*)o->agt_gen, args, nargs); | ||||||||||||||||||||||||||||||||||
if (o->agt_args) { | ||||||||||||||||||||||||||||||||||
retval = async_gen_unwrap_value(o->agt_gen, retval); | ||||||||||||||||||||||||||||||||||
if (retval == NULL) { | ||||||||||||||||||||||||||||||||||
o->agt_gen->ag_running_async = 0; | ||||||||||||||||||||||||||||||||||
o->agt_state = AWAITABLE_STATE_CLOSED; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
return retval; | ||||||||||||||||||||||||||||||||||
|
@@ -2223,6 +2259,7 @@ async_gen_athrow_throw(PyAsyncGenAThrow *o, PyObject *const *args, Py_ssize_t na | |||||||||||||||||||||||||||||||||
return NULL; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
if (retval == NULL) { | ||||||||||||||||||||||||||||||||||
o->agt_gen->ag_running_async = 0; | ||||||||||||||||||||||||||||||||||
o->agt_state = AWAITABLE_STATE_CLOSED; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration) || | ||||||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.