Repository navigation
Coordinate graceful shutdown and cancellation across daemon transports - #727
Conversation
Pre-merge review and validationReviewed the complete PR after merging the current Windows, Go 1.27.3
WSL2, Ubuntu 24.04, Linux/amd64, Go 1.27.3
Docker
CI at the reviewed head
Validation note: running the complete Windows and WSL suites concurrently caused a fixed-port collision in existing etcd fixtures on localhost port 2380. Running the suites separately passed in both environments, including the complete race suites; the collision was not a shutdown regression. Deployment contractExisting config files remain usable. The new optional This addresses the cooperative SIGINT/SIGTERM scenario in #209. SIGKILL, crashes, unavailable storage and recovery of persistent locks without TTL remain outside this guarantee. |
Summary
Coordinate daemon shutdown across native gRPC, HTTP, gRPC-Web, TLS, both cmux implementations, experimental split listeners and ACME. Stop admitting requests, drain active calls within a configurable
shutdown_timeout(30 seconds by default), then cancel remaining calls and close their transports. Keep payment storage available until request handlers and their deferred commit/rollback and unlock operations finish.Own and join background work for metering, notifications, training status updates, certificate reload and contract subscriptions. Close proxy clients and listeners, preserve request cancellation through backend calls, and bound external RPC/HTTP work and etcd transaction retries. Process backends now start before stdin is copied, avoiding an uncancellable wait on a full pipe.
Regression coverage
Validation
go test ./... -count=1 -timeout=180spassed on Windows.golangci-lint run --config=.golangci.yml --timeout=3m ./...: no issues.Shutdown contract and limits
shutdown_timeoutlimits the graceful phase, not total process lifetime. After cancellation, payment cleanup uses independent bounded storage requests; shutdown waits for those handlers before closing etcd. These independent contexts are intentional, so caller cancellation does not prevent unlocking.Cleanup cannot guarantee a successful unlock when etcd is unavailable. SIGKILL, crashes, power loss and arbitrary code that ignores cancellation are outside the cooperative shutdown guarantee. Persistent payment locks still have no TTL; crash recovery remains separate work.
Fixes #209