Repository navigation
fix(test): Stop TestServerHandlesLoadsOfPendingTasks deadlocking - #76
Merged
Merged
Conversation
The test opened a subscriber, discarded the response, and never closed the body or the Server. The SSE handler kept that connection open, so the deferred httptest.Server.Close blocked in its wait for outstanding requests. Whether it finished depended on whether the runtime had released the connection by then, so the build failed about once in five runs with a test timeout. The subscriber now closes, which cancels the request context and lets the handler return. This is what the neighbouring test already does. The WaitGroup is gone with it. http.Get returns once the handler flushes the SSE response headers, so nothing was needed to hold the connection open while the comments published.
tanderson-ld
approved these changes
Sep 16, 2026
keelerm84
pushed a commit
that referenced
this pull request
Oct 7, 2026
🤖 I have created a release *beep* *boop* --- ## [1.14.1](v1.14.0...v1.14.1) (2026-10-07) ### Bug Fixes * Keep the write error in the chain of Encoder errors ([#81](#81)) ([49bd77d](49bd77d)) * **test:** Stop TestServerHandlesLoadsOfPendingTasks deadlocking ([#76](#76)) ([d51d9b0](d51d9b0)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TestServerHandlesLoadsOfPendingTasksdeadlocks intermittently and fails the build withpanic: test timed out. Onmainat90772ecit reproduced at iteration 6 of 20 running the test alone, and at iteration 4 of 20 running the full suite.The test opened a subscriber with
http.Get, discarded the response, and never closed the body or theServer. The SSE handler kept that connection open indefinitely, so the deferredhttptest.Server.Close()blocked in its wait-for-outstanding-requests loop. The goroutine dump puts the test atserver_test.go:76insidenet/http/httptest.(*Server).Close. Whether it finished depended on whether the runtime had released the connection by then, which is what made it intermittent.Closing the subscriber cancels the request context, so the handler returns and
httptestcan finish.TestServerHandlerReceivesPublishedEventsright below it already does exactly this.The
sync.WaitGroupgoes away with it.http.Getreturns once the handler flushes the SSE response headers, so nothing was needed to hold the connection open across the publish loop -- the WaitGroup only delayed the goroutine's exit, and the goroutine was not doing anything after theGet.Defer order is load-bearing and called out in a comment: the subscriber disconnects, then the
Serverstops, thenhttptestwaits for the handler. Each step is what lets the next one finish.Verification
-race.Origin
Found while verifying #75. That change touches only the client's error-response path, and this flake reproduces on
mainwithout it, so the two are independent.Note
Overview
Fixes an intermittent test timeout in
TestServerHandlesLoadsOfPendingTasksby tearing down the SSE subscriber and server in a defined order instead of leaving an openhttp.Getconnection.The test now keeps the subscriber connected during the 1000
PublishCommentcalls (response body held open untildefer resp.Body.Close()), addsdefer server.Close(), and drops thesync.WaitGroup+ background goroutine pattern that did not actually coordinate shutdown. Comments document why defer order matters: close the body first so the handler exits, then stop theServer, then lethttptestfinish waiting.Reviewed by Cursor Bugbot for commit bc26350. Bugbot is set up for automated code reviews on this repo. Configure here.