Repository navigation
Description
Hit while running the #321 wire lane (TestManualOnTheWire, deepseek/deepseek-v4-flash): the run went silent mid-question and stayed silent for 26 minutes with the process asleep on 27s of CPU. SIGQUIT named it — two goroutines of the same hedge race, each holding the lock the other is waiting for.
The two orders
streamWatch.mu → hedgeRace.mu — internal/provider/waitreport.go, streamWatch.facts:
w.mu.Lock()
facts := waitFacts{
lane: w.race.askedLane(w.arm), // <- takes race.mu while holding w.mu
...
}
w.mu.Unlock()
facts.arms, facts.waste, facts.note = w.race.spend(w.arm) // correctly outsidehedgeRace.mu → streamWatch.mu — internal/provider/hedge.go, hedgeRace.spend:
r.mu.Lock()
defer r.mu.Unlock()
for _, other := range r.arms {
if other.index != arm {
waste += r.estimateLocked(laneOf(other), other.watch.written())
// laneOf -> other.watch.lane() -> watch.mu, and written() -> watch.mu,
// both while holding race.mu
}
}Two arms of one race recording their rows at the same time is all it takes: arm A is inside facts holding watchA.mu and waiting on race.mu; arm B is inside spend holding race.mu and walking every arm's watch, including watchA.
The stacks, from the run
goroutine 913 [sync.Mutex.Lock, 26 minutes]:
provider.(*hedgeRace).askedLane hedge.go:940 <- wants race.mu
provider.(*streamWatch).facts waitreport.go:262 <- holds watch(0x…65 9e0).mu
provider.(*Client).record calllog.go:237
provider.(*Client).send retry.go:212
goroutine 979 [sync.Mutex.Lock, 26 minutes]:
provider.(*streamWatch).lane armwatch.go:321 <- wants watch(0x…65 9e0).mu
provider.laneOf hedge.go:1072
provider.(*hedgeRace).spend hedge.go:962 <- holds race.mu
provider.(*streamWatch).facts waitreport.go:273
provider.(*Client).record calllog.go:237
provider.(*Client).send retry.go:212
Everything above them piles up behind it: hedgeRace.count and hedgeRace.hears sit on race.mu for the same 26 minutes, the turn never ends, and the caller's own 6-minute context does not help — the goroutines are parked on a mutex, not on the request.
What it costs
The turn never finishes and the surface shows a session that is visibly working and saying nothing. It needs a race that actually hedged (two arms) and both arms recording at once, so it is rare and it is not rare enough: it cost one whole measurement pass of 47 questions.
Replication
Deterministic, no model, no network — two goroutines against one race with two armed watches:
// internal/provider, -race, run it a few hundred times
func TestTwoArmsRecordingAtOnceDoNotDeadlock(t *testing.T) {
race := aRaceWithTwoArmedWatches(t) // both arms have a streamWatch
done := make(chan struct{}, 2)
for _, arm := range []int{0, 1} {
go func() { _, _ = race.arms[arm].watch.facts(); done <- struct{}{} }()
}
for range 2 {
select {
case <-done:
case <-time.After(5 * time.Second):
t.Fatal("two arms recording their rows deadlocked")
}
}
}The wire lane reproduces it too, but only by luck: go test -tags e2e -count=1 -run TestManualOnTheWire ./internal/e2e/ and wait for a question the router hedges.
Acceptance
- The test above passes a few hundred consecutive runs under
-race. - No path in
internal/providertakesstreamWatch.muandhedgeRace.muin both orders. The narrow fix is one line at the seam:factsalready readsspendoutsidew.mu, andaskedLaneshould be read the same way — take both race readings before or after thew.musection, never inside it. - A wire pass of
TestManualOnTheWireruns 47 questions end to end without going silent.
Drafted with CodeAF · reviewed and owned by the author
Activity
santoshkumarradha commentedon Sep 2, 2026
Provenance and preservation for the run that produced these stacks, added so the artifact outlives the lane's worktree.
~/aforge-casualties/2026-09-02-wire-deadlock-with-1.logon this machine (2,172 lines, the fullSIGQUITdump of all 102 goroutines from line 580), with the pass driver beside it (2026-09-02-wire-run.sh) and a provider/session-only extract (2026-09-02-wire-deadlock-goroutines.txt).~/af-321onfix/321-manual-cue, basedevat 5448493, plus the cue work later committed as 6963962.fc1f4561(PR lanes: the belief write leaves the send path, and no lock in this package waits #317, the fix for lane ledger: a belief write on the send path holds a process-wide mutex across a blocking flock — one stuck lock silences the wire for the whole process #264) is an ancestor of that tree.SIGQUITat 01:19:27 (2017s). lanes: the belief write leaves the send path, and no lock in this package waits #317 landed at 00:14 local, thirty minutes before the pass began — so this is not lane ledger: a belief write on the send path holds a process-wide mutex across a blocking flock — one stuck lock silences the wire for the whole process #264 reopened. lane ledger: a belief write on the send path holds a process-wide mutex across a blocking flock — one stuck lock silences the wire for the whole process #264 was a process-wide mutex ininternal/laneheld across a blocking flock; this is a lock-order inversion betweenhedgeRace.muandstreamWatch.muinsideinternal/provider. Different lock, different package, same symptom from outside: a wire that goes quiet with the process asleep.it keeps summarizing the conversation) never returned. Nothing from that pass was pooled; it was re-run from scratch.provider: prevent hedge row lock inversion (#438)
provider: prevent hedge row lock inversion (#438)