fix(server): guard Shutdown against a server that never started - #251
Open
kazz187 wants to merge 1 commit into
Open
fix(server): guard Shutdown against a server that never started#251kazz187 wants to merge 1 commit into
kazz187 wants to merge 1 commit into
Conversation
Splitting ListenAndServe moved the s.server assignment after the bind, so a failed bind (a port already in use, for example) now returns early and leaves s.server nil. cmd/taskguild-server cancels its context on that error and then calls Shutdown unconditionally, turning what used to be a single logged error into a nil-pointer panic. Also add regression tests for the gRPC trailer path over h2c, which is the part most at risk from swapping the HTTP/2 implementation, and drive test teardown through Shutdown so the path whose semantics changed with native h2c is actually exercised.
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.
Follow-up to #249, from the review of that change.
Summary
Fix a nil-pointer panic introduced by refactor(server): replace deprecated h2c handler with http.Server.Protocols #249. Splitting
ListenAndServemoved thes.serverassignment after the bind, so a failed bind (a port already in use, for example) returns early and leavess.servernil.cmd/taskguild-server/run.gocancels its context on that error and then callsShutdownunconditionally, so what used to be a single logged error became a panic:Before refactor(server): replace deprecated h2c handler with http.Server.Protocols #249 the
*http.Serverwas assigned before binding, soShutdownwas always safe.Shutdownis now a no-op when the server never started.Add a gRPC trailer regression test over h2c. Trailers are mandatory in the gRPC protocol (
grpc-statusis sent as one) and are the part most at risk from swapping the HTTP/2 implementation fromgolang.org/x/net/http2to the one built intonet/http. refactor(server): replace deprecated h2c handler with http.Server.Protocols #249 verified this only by hand. The test hits/grpc.health.v1.Health/Check, which bypassesapiKeyMiddlewareand needs no injected services.Add a regression test for
Shutdownafter a failed listen, covering the panic above.Drive test teardown through
Shutdowninstead of only closing the listener. This is the path whose semantics changed most when h2c stopped hijacking connections, and it was previously untested; it also reaps the connection goroutines.Extract a
newTestServerhelper to remove the duplicated nil×16 construction.Test plan
go build ./...andgo vet ./internal/go test ./... -count=1— all packages passgo test ./internal/ -race -count=5— passes, no flakesgo tool golangci-lint run ./internal/ --max-issues-per-linter 0 --max-same-issues 0— 2 findings, both pre-existing (gosecG112,ST1000); no new findingsgofmt -l internal/— cleanShutdownnil guard →TestShutdownAfterListenFailurefails with the original panicSetUnencryptedHTTP2→ h2c and trailer tests fail, HTTP/1.1 still passesSetHTTP1→ only the HTTP/1.1 case failsNotes
The unsynchronized read/write of
Server.serverbetween theServegoroutine andShutdownon the main goroutine still exists and is tracked separately. The guard here stops the panic but does not make the field race-free.