Repository navigation
fix: initialize the HTTP server before serving - #259
Merged
Merged
Conversation
Signed-off-by: Perfloop Agent <[email protected]>
Signed-off-by: Perfloop Agent <[email protected]>
[Medium impact] The PR appears safe to merge, with no outstanding findings. Summary
Reviews (2) · Last reviewed commit: "test: use time.After for listener pollin..." · Reviewed by Greptile |
Signed-off-by: Perfloop Agent <[email protected]>
ovaistariq
approved these changes
Oct 21, 2026
|
🎉 This PR is included in version 1.22.3 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
TAG created its
http.ServerinsideStart, whilecmd/tag.mainlaunchesStartin a goroutine and can callStopafter SIGINT or SIGTERM. A signal arriving first could makeStopsee no server and return beforeStartlater began listening.NewServernow initializes the existing server before the goroutine starts;StartandStopuse the same instance. Routes, TLS selection, timeouts, and graceful draining are unchanged, and no configuration or protocol surface is added.TestServerStartStopLifecycleis the defect regression: on the test-only comparison, whose server implementation is unchanged from the base, it observes/healthsucceeding afterStopand reports the Start/Stop race; it passes with the fix. Listener readiness polling now waits ontime.Afterrather thantime.Sleep, following the repository's concurrent-test rule.TestServerShutdownDrainsHTTPAndTLSis separate preservation coverage, not the race regression. It passes on the same test-only comparison and with the fix, holding HTTP and HTTPSListMultipartUploadsrequests in a test forwarder until the listener closes and verifying each response completes. The handler package tests, focused race tests, targeted vet, formatting checks, andmake buildpass.This condition holds with this change and does not hold at
adbeaa624ce0b90a83352ef289f997783aa9682d:Within TAG's supported one-start cmd/tag.main lifecycle, after NewServer and any SetTLS call complete before Start is launched, Start and Stop use the same fully initialized http.Server without unsynchronized access to its pointer, and a Stop completed before Start prevents listener startup..The small runner used to compare the native lifecycle test on the original and fixed source is retained separately; it is not part of this pull request. The regression tests are included. Production signal frequency and user-visible impact were not measured.
The broader
make test,make lint-ci,make test-integration,make test-race, andmake test-coveragesuites remain for repository CI.Generated by Perfloop.
Note
Medium Risk
Touches core server lifecycle and shutdown ordering; behavior is intended to be equivalent aside from preventing post-Stop listener startup.
Overview
Fixes a Start/Stop race where
http.Serverwas created only insideStart, so an earlyStop(e.g. SIGTERM before the listen goroutine ran) could no-op whileStartstill opened the listener later.NewServernow builds thehttp.Server(address, router, timeouts) beforeStartruns in another goroutine;Startonly callsListenAndServe/ListenAndServeTLSon that shared instance. TLS, routes, and shutdown draining behavior are unchanged.Adds
handlers/server_lifecycle_test.go: regression tests for stop-before-start, concurrent start/stop (100 iterations), and HTTP/HTTPS shutdown draining in-flight requests.Reviewed by Cursor Bugbot for commit 5034f76. Bugbot is set up for automated code reviews on this repo. Configure here.