Skip to content

Commit be578a2

Browse files
lioraronclaude
andauthored
fix(pipeline): resolve flaky TestBroadcaster_RetriesTransientError synctest deadlock (llm-d#593)
The test used synctest.Test but did not ensure all broadcaster goroutines exited before the bubble closed. After cancel(), the fake client could produce results faster than they were drained, filling the subscriber channel buffer and blocking safeChannelSend — triggering a synctest deadlock panic. Fix: make the fake client context-aware so it stops producing results after cancellation, and explicitly cancel + drain before returning. Closes llm-d#592 Signed-off-by: Lior Aronovich <lioraronpr@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ef6e111 commit be578a2

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

internal/processor/pipeline/async_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ func TestBroadcaster_RetriesTransientError(t *testing.T) {
275275

276276
client := &fakeAsyncClientWithErrors{
277277
getResult: func(ctx context.Context) (*inference.GenerateResponse, error) {
278+
if ctx.Err() != nil {
279+
return nil, ctx.Err()
280+
}
278281
n := callCount.Add(1)
279282
if n <= 3 {
280283
return nil, transientErr
@@ -292,7 +295,6 @@ func TestBroadcaster_RetriesTransientError(t *testing.T) {
292295
broadcaster.Subscribe(resultCh)
293296

294297
ctx, cancel := context.WithCancel(t.Context())
295-
defer cancel()
296298
go broadcaster.Run(ctx)
297299

298300
// Advance past backoff sleeps: 100ms + 200ms + 400ms = 700ms
@@ -314,6 +316,18 @@ func TestBroadcaster_RetriesTransientError(t *testing.T) {
314316
if n := callCount.Load(); n < 4 {
315317
t.Fatalf("GetResult called %d times, want >= 4 (3 errors + 1 success)", n)
316318
}
319+
320+
// Cancel and drain resultCh so broadcaster goroutines can exit
321+
// before the synctest bubble closes.
322+
cancel()
323+
for {
324+
synctest.Wait()
325+
select {
326+
case <-resultCh:
327+
default:
328+
return
329+
}
330+
}
317331
})
318332
}
319333

0 commit comments

Comments
 (0)