Repository navigation
fix(server): cancel the calls left after the grace, and wait for them - #17
Merged
Merged
Conversation
The context of a call came from the connection, not from Run's: a SIGTERM shut the server down, but never cancelled a call. After -shutdown-timeout, Run returned with the calls still running, and main exited at once: the commands of those calls ran on, outside a container, and their temporary directories, which hold the uploads with their metadata, stayed. Each call's context now comes from Run's, without its end: a SIGTERM still leaves the calls their grace. When the grace is over, Run cancels the calls left, which stops their commands (exec.CommandContext), closes their connections, and waits for their handlers, which remove their directories, before it returns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
The ctx that
maingets fromsignal.NotifyContextreachedserver.Run, but no call ever received it. On SIGTERM:Shutdownstopped taking new calls and waited for the ones in flight. That part was right.-shutdown-timeoutrunning out did not cancel it.Runreturned an error with those calls still running, andmaincalledos.Exit(1). That skipped the deferred cleanups:Changes
http.Server.BaseContextgives each call a ctx derived from Run's ctx throughcontext.WithoutCancel. It keeps the ctx's values but is not cancelled by SIGTERM itself, so in-flight calls keep their grace.exec.CommandContext;srv.Close();-shutdown-timeoutrow now says that the calls still running are cancelled and their files removed.Tests
TestShutdownLetsCallsFinish: a call shorter than the grace is not cancelled and answers normally, and Run returns nil.TestShutdownCancelsCallsAfterGrace: a call that never ends is cancelled after the grace, and Run returns only after its handler has finished cleaning up.context deadline exceeded, and Run returns before the handler.scripts/lint.shandgo test -race ./internal/...pass.🤖 Generated with Claude Code