fix(cli): close coderd on server startup errors - #30280
Open
ibetitsmike wants to merge 1 commit into
Open
ibetitsmike wants to merge 1 commit into
ibetitsmike wants to merge 1 commit into
Conversation
`coder server` closed the coderd API only in its shutdown sequence, so every startup error returned after the API was created leaked the whole instance (tailnet, chatd, metricscache, pubsub queues). In CI, TestServer/Logging hits this when cleanup cancels startup while aibridged is being created, and the cli package goleak check fails. Close the API in a defer right after it is created and reuse the same call in the shutdown sequence. A sync.OnceValue guards it because the closer is not safe to call twice.
ibetitsmike
marked this pull request as ready for review
October 2, 2026 12:34
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
jscottmiller
approved these changes
Oct 2, 2026
This branch has not been deployed
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.
coder servercloses the coderd API only in its graceful shutdown sequence. Every startup error returned afternewAPI(creating aibridged, registering Prometheus metrics, writing the config URL, creating provisioner daemons, notifying systemd) skipped that close and leaked the whole coderd instance: tailnet and wireguard-go, gvisor, metricscache, dbrollup, cryptokeys, chatd, and pubsub queues.TestServer/Logginghits this when test cleanup cancels startup while aibridged is being created. The test helper ignores the resultingcontext cancelederror, so only the package-level goleak check inclifails.The fix closes the API in a deferred
sync.OnceValueregistered right afternewAPI, and the shutdown sequence calls the same function. The guard is needed because the closer is not safe to call twice: the AGPL API returns "API already closed", and the enterprise closer closes each component again. The normal shutdown path is unchanged.Testing
The new
TestServer/StartupErrorNoLeakfails startup after coderd is created by putting a directory at the config URL path.go test ./cli -run '^TestServer$/^StartupErrorNoLeak$' -count=1exited 1 in 3 of 3 runs withgoleak: Errors on successful test run: found unexpected goroutines(coderd frames) while the subtest passed.TestServer/Loggingalone, 20 runs from one test binary: 20 of 20 passed with no goleak failure, including 3 runs that hit thecreate aibridgedstartup error.go test ./cli -count=1passed in 4 of 4 runs, andgo vet ./cliis clean.Found in the CI of #30272 (
test-go-pg (ubuntu-latest)).