Skip to content
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

gh-115103: Fix unregistering of QSBR state #116480

Merged
merged 1 commit into from
Mar 8, 2024

Conversation

colesbury
Copy link
Contributor

@colesbury colesbury commented Mar 7, 2024

If a thread blocks while waiting on the shared->mutex lock, the array of QSBR states may be reallocated. In other words, the value oftstate->qsbr may be different before and after the PyMutex_Lock() call, and using the previous value across the lock acquisition is not safe.

If a thread blocks while waiting on the `shared->mutex` lock, the array
of QSBR states may be reallocated. The `tstate->qsbr` values before the
lock is acquired may not be the same as the value after the lock is acquired.
@colesbury colesbury requested a review from DinoV March 7, 2024 23:02
colesbury added a commit to colesbury/cpython that referenced this pull request Mar 7, 2024
In general, when `_PyThreadState_GET()` is non-NULL then the current
thread is "attached", but there is a small window during
`PyThreadState_DeleteCurrent()` where that's not true:
tstate_delete_common is called when the thread is detached, but before
current_fast_clear().

This updates _PySemaphore_Wait() to handle that case.
Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@colesbury colesbury merged commit cca3023 into python:main Mar 8, 2024
37 checks passed
@colesbury colesbury deleted the gh-115103-unregister branch March 8, 2024 17:39
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
If a thread blocks while waiting on the `shared->mutex` lock, the array
of QSBR states may be reallocated. The `tstate->qsbr` values before the
lock is acquired may not be the same as the value after the lock is acquired.
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
If a thread blocks while waiting on the `shared->mutex` lock, the array
of QSBR states may be reallocated. The `tstate->qsbr` values before the
lock is acquired may not be the same as the value after the lock is acquired.
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.

2 participants