Go "panic: test timed out" - Fix in CI
go test enforces a per-binary timeout (10m by default) and panics with a full goroutine dump when exceeded. The dump usually points at a goroutine stuck on a channel, lock, or network call.
What this error means
A test run aborts with panic: test timed out after 10m0s and a goroutine dump. A test hung instead of completing, or the suite legitimately needs more time.
panic: test timed out after 10m0s
goroutine 34 [chan receive]:
example.com/app.TestSync(...)
sync_test.go:42 +0x...Common causes
A test hung
A goroutine blocked forever on a channel, lock, or network call, so the suite never finished.
Timeout too low for the suite
A genuinely long suite exceeded the default 10m timeout.
How to fix it
Fix the hang
- Read the goroutine dump to find the blocked test and add a timeout or close the channel.
ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
defer cancel()Raise the timeout for long suites
- Increase -timeout only when the suite legitimately needs it.
go test -timeout 20m ./...How to prevent it
- Bound every blocking operation in tests with a context timeout.
- Investigate hangs from the goroutine dump rather than just raising -timeout.
- Split slow suites so each binary finishes within budget.