Uh oh!
There was an error while loading. Please reload this page.
gh-120321: Lock gen_send - #120327
Conversation
markshannon
commented
Jun 11, 2024
What's the root cause of #120321? This feels like slapping a lock on something and hoping it works. |
Fidget-Spinner
commented
Jun 11, 2024
The crash's root cause is here https://github.com/python/cpython/pull/120327/files#diff-2a0c449b68605ebd0872fd232e60ce7e838a77782a6d2e364764f99514fb508aR219 Those 3 lines can race and cause I locked the whole thing because TSAN is warning not just those few lines. It warns that the _PyFrame_StackPush and all the other stack accessor functions in there are racing as well. Though I don't think that results in a crash. |
markshannon
commented
Jun 11, 2024
What about all the other places that I suspect that this doesn't crash only because specialization is turned off for free-threading: defgen():
whileTrue:
yielddefmy_next(it):
forvalinit:
returnvalueraiseStopIterationit=gen()
withconcurrent.futures.ThreadPoolExecutor() asexecutor:
whileTrue:
_=executor.submit(lambda: my_next(it)) |
Yeah the entire gen_send has multiple races in multiple places. Likewise for the specializing interpreter. So the entire thing needs to be locked (what the GIL does at the moment). |
markshannon
commented
Jun 11, 2024
Pushing and popping generator frames needs to be locked. The best way to do that would be to move popping and pushing into its own helper function. |
Fidget-Spinner
commented
Jun 11, 2024
I agree that pushing and popping frames need fixing, but |
markshannon
commented
Jun 11, 2024
OOI, what are the other crashes? |
Fidget-Spinner
commented
Jun 12, 2024
A selection of them after I've locked just the frame pushing |
DinoV
commented
Jun 12, 2024
I wonder if we really only need the locks up to the transition to I think other than the asserts that only leaves |
vstinner
commented
Nov 6, 2024
What's the status of this PR? It now has multiple merge conflicts. |
Adds per-object lock for gen_send to fix crashes.