v0.1.1: threading wait(timeout) deadlock fix#268
Merged
Conversation
Pre-v0.1.1, every threading.Condition.wait(timeout=...), Event.wait(timeout), and Semaphore.acquire(timeout) call hung on sync.Cond.Wait, which has no timeout. The Go deadlock detector killed the process with "all goroutines are asleep - deadlock!". This release replaces sync.Cond with chCond, a channel-backed notifier. Each Wait() registers a fresh channel; the FIFO of waiters is woken by Notify(n) or Broadcast(); timeout via select + time.After. What's wired: - Event.wait(timeout=None) - Condition.wait(timeout=None) — returns True if notified, False on timeout - Condition.wait_for(predicate, timeout=None) — returns last predicate result - Condition.notify(n) — wakes up to n waiters (was always Signal-one) - Semaphore.acquire(blocking, timeout) - Barrier.wait(timeout) — on timeout, breaks the barrier threading.BrokenBarrierError (subclass of RuntimeError) is now exposed as a real class on the threading module instead of a bare RuntimeError with a "BrokenBarrierError" message. First release of the v0.1.x cycle. Spec at notes/Spec/1500/1542_goipy_v0101_condition_timeout.md; fixture 347 covers all four primitives across timeout-expired and notified-before-timeout paths. Closes V1 from notes/Spec/1500/1541_goipy_v01x_roadmap.md.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
sync.CondwithchCond(channel-backed notifier with timeout) insidevm/stdlib_threading.go. Pre-v0.1.1Condition.wait(timeout=…),Event.wait(timeout=…),Semaphore.acquire(timeout=…),Barrier.wait(timeout=…)hung onsync.Cond.Waitand tripped Go's deadlock detector.timeoutthrough every primitive that takes one;Condition.notify(n)now wakes up to n waiters instead of always Signal-one.threading.BrokenBarrierErroras a real subclass ofRuntimeErroron the threading module.First release of the v0.1.x cycle (roadmap at
notes/Spec/1500/1541_goipy_v01x_roadmap.md, V1). Spec atnotes/Spec/1500/1542_goipy_v0101_condition_timeout.md.Test plan
go build ./...go test ./vm/ -run TestFixtures— all 347 fixtures pass/tmp/probe_v01x_thr2.pyno longer deadlocks;Condition.wait(timeout=0.05)returns False after ~50ms as expected