Skip to content

fix: initialize the HTTP server before serving - #259

Merged
ovaistariq merged 3 commits into
mainfrom
perfloop-pr-open-mxytzfzewx
Oct 21, 2026
Merged

ovaistariq merged 3 commits into
mainfrom
perfloop-pr-open-mxytzfzewx

Conversation

@perfloop

@perfloop perfloop Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

TAG created its http.Server inside Start, while cmd/tag.main launches Start in a goroutine and can call Stop after SIGINT or SIGTERM. A signal arriving first could make Stop see no server and return before Start later began listening. NewServer now initializes the existing server before the goroutine starts; Start and Stop use the same instance. Routes, TLS selection, timeouts, and graceful draining are unchanged, and no configuration or protocol surface is added.

TestServerStartStopLifecycle is the defect regression: on the test-only comparison, whose server implementation is unchanged from the base, it observes /health succeeding after Stop and reports the Start/Stop race; it passes with the fix. Listener readiness polling now waits on time.After rather than time.Sleep, following the repository's concurrent-test rule.

TestServerShutdownDrainsHTTPAndTLS is separate preservation coverage, not the race regression. It passes on the same test-only comparison and with the fix, holding HTTP and HTTPS ListMultipartUploads requests in a test forwarder until the listener closes and verifying each response completes. The handler package tests, focused race tests, targeted vet, formatting checks, and make build pass.

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, and make test-coverage suites 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.Server was created only inside Start, so an early Stop (e.g. SIGTERM before the listen goroutine ran) could no-op while Start still opened the listener later.

NewServer now builds the http.Server (address, router, timeouts) before Start runs in another goroutine; Start only calls ListenAndServe / ListenAndServeTLS on 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.

@greptile-apps

greptile-apps Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no outstanding findings.

Summary

NewServer now creates the http.Server before Start runs, so Start and Stop share the same instance.

  • Start and Stop use the HTTP server created by NewServer.

Reviews (2) · Last reviewed commit: "test: use time.After for listener pollin..." · Reviewed by Greptile

Comment thread handlers/server_lifecycle_test.go Resolved
@ovaistariq
ovaistariq merged commit 45b3f0a into main Oct 21, 2026
12 of 13 checks passed
@ovaistariq
ovaistariq deleted the perfloop-pr-open-mxytzfzewx branch October 21, 2026 06:16
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 21, 2026
@tigrisdata-argocd-bot

Copy link
Copy Markdown

🎉 This PR is included in version 1.22.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants