gh-114944: Fix race between _PyParkingLot_Park and _PyParkingLot_UnparkAll when handling interrupts#114945
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There is a potential race when
_PyParkingLot_UnparkAllis executing in one thread and another thread is unblocked because of an interrupt in_PyParkingLot_Park. Consider the following scenario:_PyParkingLot_Parkon addressA._PyParkingLot_UnparkAllon addressA. It finds thewait_entryforT0and unlinks2 its list node.To fix this we mark each waiter as unparking before releasing the bucket lock.
_PyParkingLot_Parkwill wait to handle the coming wakeup, and not attempt to unlink the node, when this field is set._PyParkingLot_Unparkdoes this already, presumably to handle this case._PyParkingLot_Parkand_PyParkingLot_UnparkAllwhen handling interrupts #114944Footnotes
https://github.com/python/cpython/blob/f35c7c070ca6b49c5d6a97be34e6c02f828f5873/Python/parking_lot.c#L303↩
https://github.com/python/cpython/blob/f35c7c070ca6b49c5d6a97be34e6c02f828f5873/Python/parking_lot.c#L369↩
https://github.com/python/cpython/blob/f35c7c070ca6b49c5d6a97be34e6c02f828f5873/Python/parking_lot.c#L320↩