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

Issues when Condition.notify() is interrupted #92530

Closed
serhiy-storchaka opened this issue May 9, 2022 · 2 comments · Fixed by #92534
Closed

Issues when Condition.notify() is interrupted #92530

serhiy-storchaka opened this issue May 9, 2022 · 2 comments · Fixed by #92534
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

If threading.Condition.notify() is interrupted just after it releases the waiter lock, but before remove it from the queue, the following calls of notify() will fail with RuntimeError: cannot release un-acquired lock. It can block the waiter threads if they do not use timeout.

cpython/Lib/threading.py

Lines 375 to 380 in 5bc2390

for waiter in waiters_to_notify:
waiter.release()
try:
all_waiters.remove(waiter)
except ValueError:
pass

The simplest solution would be to silence a RuntimeError in waiter.release(). There may be similar issues in other parts of the code.

@serhiy-storchaka serhiy-storchaka added the type-bug An unexpected behavior, bug, or error label May 9, 2022
@serhiy-storchaka serhiy-storchaka self-assigned this May 9, 2022
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue May 9, 2022
@serhiy-storchaka
Copy link
Member Author

There was a similar issue in #89437, although it is difficult to fix it correctly in that case. @vstinner

@bensimner
Copy link

In #90882 the discussion led to a solution of adding threading.Thread.acquire_and_release method which would solve #89437, but I don't think a PR for that was ever created. This solution probably doesn't help here.

Simply ignoring the RuntimeError here would mean that in those cases notify(n) would wake up fewer than n threads even if n threads were available to wake. Possibly that's not an issue since condition vars don't make guarantees about how many threads will be awoken.

serhiy-storchaka added a commit that referenced this issue May 16, 2022
…dition.notify (GH-92534)

If Condition.notify() was interrupted just after it released the waiter lock,
but before removing it from the queue, the following calls of notify() failed
with RuntimeError: cannot release un-acquired lock.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 16, 2022
…ng.Condition.notify (pythonGH-92534)

If Condition.notify() was interrupted just after it released the waiter lock,
but before removing it from the queue, the following calls of notify() failed
with RuntimeError: cannot release un-acquired lock.
(cherry picked from commit 70af994)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 16, 2022
…ng.Condition.notify (pythonGH-92534)

If Condition.notify() was interrupted just after it released the waiter lock,
but before removing it from the queue, the following calls of notify() failed
with RuntimeError: cannot release un-acquired lock.
(cherry picked from commit 70af994)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 16, 2022
…ng.Condition.notify (pythonGH-92534)

If Condition.notify() was interrupted just after it released the waiter lock,
but before removing it from the queue, the following calls of notify() failed
with RuntimeError: cannot release un-acquired lock.
(cherry picked from commit 70af994)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
ambv pushed a commit that referenced this issue May 16, 2022
…dition.notify (GH-92534) (GH-92831)

If Condition.notify() was interrupted just after it released the waiter lock,
but before removing it from the queue, the following calls of notify() failed
with RuntimeError: cannot release un-acquired lock.
(cherry picked from commit 70af994)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
ambv pushed a commit that referenced this issue May 16, 2022
…dition.notify (GH-92534) (GH-92830)

If Condition.notify() was interrupted just after it released the waiter lock,
but before removing it from the queue, the following calls of notify() failed
with RuntimeError: cannot release un-acquired lock.
(cherry picked from commit 70af994)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington added a commit that referenced this issue May 17, 2022
…ing.Condition.notify (GH-92534) (GH-92829)

If Condition.notify() was interrupted just after it released the waiter lock,
but before removing it from the queue, the following calls of notify() failed
with RuntimeError: cannot release un-acquired lock.
(cherry picked from commit 70af994)


Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>

Automerge-Triggered-By: GH:serhiy-storchaka
hello-adam pushed a commit to hello-adam/cpython that referenced this issue Jun 2, 2022
…ng.Condition.notify (pythonGH-92534) (pythonGH-92831)

If Condition.notify() was interrupted just after it released the waiter lock,
but before removing it from the queue, the following calls of notify() failed
with RuntimeError: cannot release un-acquired lock.
(cherry picked from commit 70af994)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
2 participants