Refactor cmd HTTP server lifecycle into shared serveAndWait helper - #7104
Conversation
There was a problem hiding this comment.
Pull request overview
This PR centralizes the duplicated HTTP server serve/cancel/shutdown lifecycle used by the gateway root command and the proxy subcommand into a shared serveAndWait(...) helper, standardizing shutdown timeout behavior and adding focused test coverage for graceful shutdown.
Changes:
- Added
internal/cmd/serve.gowith a sharedserveAndWait(...)helper and a common shutdown timeout constant. - Refactored
internal/cmd/root.goandinternal/cmd/proxy.goto useserveAndWait(...)instead of inline lifecycle logic. - Added
internal/cmd/serve_test.goto validate graceful shutdown behavior.
Show a summary per file
| File | Description |
|---|---|
| internal/cmd/serve.go | Introduces shared serve/shutdown helper and shared shutdown timeout constant. |
| internal/cmd/serve_test.go | Adds test coverage for the shared helper’s graceful shutdown behavior. |
| internal/cmd/root.go | Replaces inline HTTP server lifecycle logic with serveAndWait(...) usage. |
| internal/cmd/proxy.go | Replaces inline proxy server lifecycle logic with serveAndWait(...) usage and removes duplicated timeout constant. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 5
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Fixed in |
run()ininternal/cmd/root.goandrunProxy()ininternal/cmd/proxy.goduplicated the same serve/cancel/shutdown lifecycle with diverging timeout expression and shutdown handling shape. This change centralizes that lifecycle so timeout and graceful shutdown behavior are maintained in one place.Lifecycle deduplication
internal/cmd/serve.gowithserveAndWait(...)to encapsulate:Serveexecutionhttp.Server.Shutdownwith timeoutRoot command refactor
run()withserveAndWait(...).Proxy command refactor
runProxy()withserveAndWait(...).Timeout standardization
httpServerShutdownTimeout = 5s) and removed proxy-local timeout duplication.Focused coverage
internal/cmd/serve_test.goto validate graceful shutdown behavior of the shared helper.