fix: data race on the bodyReadTimeout test global (TestStreamingSurvivesBodyDeadline) #539
Labels
No labels
backend
bug
chore
duplication
effort:complex
effort:medium
effort:trivial
enhancement
follow-up
frontend
fullstack
priority:high
ready-for-agent
refactor
security
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
dries/ocman#539
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Found while running
go test -race ./internal/server/during PR #538. Pre-existing on main (reproduced on a cleanorigin/maincheckout ata1cd6577, fails within 3 runs); unrelated to that PR's changes, so filed separately.Cause
TestStreamingSurvivesBodyDeadlinemutates the package-levelbodyReadTimeout(body_deadline_test.go:200) and restores it int.Cleanup(:201). The/ssehandler installed bybodyDeadlineTestServerreads the same global in its flush loop (time.Sleep(bodyReadTimeout), :55). The test returns while that handler goroutine is still sleeping/looping, so the cleanup's write races the handler's read. The listener is never shut down, so nothing joins the in-flight handler.Not a product-code bug —
bodyReadTimeoutis only written by tests — but it fails-racenon-deterministically, andmake test-raceis a documented target.Suggested fix
Any one of:
bodyReadTimeoutinto a local once at entry, so the loop doesn't re-read the global.bodyDeadlineTestServeranhttptest.Server-style shutdown (or a WaitGroup the handler signals) and join it in cleanup before restoring the global.Acceptance criteria
go test -race ./internal/server/ -run TestStreamingSurvivesBodyDeadline -count=10is clean.make test-racepasses for internal/server.