Repository navigation
test(cache): fail fast on ConcurrentDownloadCancel hang (refs #1252) - #1257
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds a local test timeout helper and applies it to the ConcurrentDownloadCancelOneClientOthersContinue test: imports ChangesTest Timeout and Diagnostics
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a runWithTimeout helper in pkg/cache/cache_test.go to prevent tests from hanging indefinitely and to provide goroutine dumps for debugging concurrency issues. This helper is integrated into the testConcurrentDownloadCancelOneClientOthersContinue test. The reviewer suggested improving the helper by using time.NewTimer for better resource management and implementing a dynamic buffer for runtime.Stack to prevent truncation of diagnostic information.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pkg/cache/cache_test.go (1)
1845-1845:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winFix compilation:
sync.WaitGroupused withwg.Go()inpkg/cache/cache_test.go
wgis declared assync.WaitGroupbutwg.Go(func() { ... })is called at ~1845/~1862 and again at ~2263/~2275;sync.WaitGrouphas noGo()method (it only hasAdd/Done/Wait), so this won’t compile—switch toerrgroup.Groupor replace withwg.Add(1)+defer wg.Done()+ direct goroutine launches.- Timeout helper (
runWithTimeout) + itsruntime.Stackgoroutine-dump on timeout and the30*time.Secondwrapping ofio.ReadAll(readerB)/wg.Wait()look correct.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/cache/cache_test.go` at line 1845, The tests declare wg as sync.WaitGroup but call wg.Go(...), which fails because sync.WaitGroup has no Go method; fix by replacing the sync.WaitGroup usage at the wg.Go call sites (references: wg.Go, wg.Wait, wg.Add/Done usage) with either an errgroup.Group (create an errgroup.Group variable and call g.Go for goroutine spawn, then g.Wait) or keep the sync.WaitGroup and change each wg.Go(func(){...}) to wg.Add(1); go func(){ defer wg.Done(); ... }(); ensuring runWithTimeout stays unchanged and continue to call wg.Wait (or g.Wait) where appropriate.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@pkg/cache/cache_test.go`:
- Line 1845: The tests declare wg as sync.WaitGroup but call wg.Go(...), which
fails because sync.WaitGroup has no Go method; fix by replacing the
sync.WaitGroup usage at the wg.Go call sites (references: wg.Go, wg.Wait,
wg.Add/Done usage) with either an errgroup.Group (create an errgroup.Group
variable and call g.Go for goroutine spawn, then g.Wait) or keep the
sync.WaitGroup and change each wg.Go(func(){...}) to wg.Add(1); go func(){ defer
wg.Done(); ... }(); ensuring runWithTimeout stays unchanged and continue to call
wg.Wait (or g.Wait) where appropriate.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d8f53b42-0a4e-435a-96b0-dec8425a8226
📒 Files selected for processing (1)
pkg/cache/cache_test.go
testConcurrentDownloadCancelOneClientOthersContinue had two un-timeout-guarded blocking calls after the existing 5-10 s t.Fatal guards: - io.ReadAll(readerB) on line 1916 - wg.Wait() on line 1932 When the shared streaming goroutine got stuck in some race with client A's cancellation (root cause unknown, not reproducible locally even under 200x stress), readerB's pipe writer never closed and io.ReadAll blocked for the full `go test -timeout` budget — observed as 20-minute hangs on CI under heavy load during the lean-flake-check measurement runs. See ncps #1252 for the original filing and the hypothesis about the shared-reader fanout path in c.GetNar. Wrap both blocking calls in a new test-only helper, runWithTimeout, that runs fn in a goroutine, fails the test if it doesn't complete within d, and dumps all goroutines via runtime.Stack on timeout. 30 s budget is generous for the streaming path but well under the 20-min outer test timeout — converting a silent hang into a fast-failing test with the exact goroutine stack at the failure point. This does NOT fix the underlying race. It makes the next occurrence diagnosable so the actual fix can land based on real data instead of speculation. Verified locally: 50/50 passing runs at -race (the bug doesn't reproduce locally; this is purely defensive instrumentation for CI). Refs #1252. Co-Authored-By: Claude Opus 4.7 <[email protected]>
Replace time.After with time.NewTimer + defer Stop() so the timer is reclaimed immediately when fn completes rather than waiting for the full duration to expire. Use a dynamic doubling buffer for runtime.Stack so the goroutine dump is never truncated in complex concurrent tests with many goroutines — the 1 MB fixed buffer could silently cut off the diagnostic information this helper exists to provide. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
0f4c62d to
9c27534
Compare
Summary
testConcurrentDownloadCancelOneClientOthersContinue had two un-timeout-guarded blocking calls after the existing 5–10 s
t.Fatalguards:io.ReadAll(readerB)(line 1916) andwg.Wait()(line 1932). When the shared streaming goroutine got stuck in some race with client A's cancellation,readerB's pipe writer never closed andio.ReadAllblocked for the fullgo test -timeoutbudget — observed as 20-minute hangs on CI under heavy load during the lean-flake-check measurement runs.This PR wraps both calls in a new test-only helper
runWithTimeout(30 s budget, dumps all goroutines viaruntime.Stackon timeout) so the next occurrence of the hang fails the test in 30 s with the exact stuck-goroutine trace instead of consuming 20 minutes of CI.What this PR does NOT do
It does not fix the underlying race. The race is non-trivial: not reproducible locally even under 200×
-race -countstress, code inspection inc.GetNar's shared-reader-fanout path is suggestive but ambiguous (see #1252 for the hypotheses), and a real fix needs goroutine-level diagnostics from an actual CI hang.Once this PR is merged and the hang fires once more in CI, the failure will print exactly which goroutine is stuck where. That data should let us pinpoint and fix the root cause cheaply.
Stack
Test plan
go test -race -count=50 -run "TestCacheBackends/SQLite/ConcurrentDownloadCancelOneClientOthersContinue" ./pkg/cache/→ 50/50 pass (the bug doesn't reproduce locally; this is purely defensive instrumentation).golangci-lint run ./pkg/cache/cache_test.go→ 0 issues after--fix.Refs #1252.
🤖 Generated with Claude Code