Skip to content

fix(server): bound graceful shutdown so SIGINT/SIGTERM cannot hang on open streams - #315

Closed
wtfsayo wants to merge 1 commit into
rivet-dev:mainfrom
wtfsayo:fix/server-graceful-shutdown-6
Closed

wtfsayo wants to merge 1 commit into
rivet-dev:mainfrom
wtfsayo:fix/server-graceful-shutdown-6

Conversation

@wtfsayo

@wtfsayo wtfsayo commented Sep 14, 2026

Copy link
Copy Markdown

Summary

Fixes #6 - Ctrl+C did not shut down the server when long-lived streams were open.

  • axum::serve(...).with_graceful_shutdown(...) waits for in-flight requests to finish. SSE streams (/v1/processes/{id}/logs?follow=true, /v1/acp/{id}, opencode compat event feeds) never complete on their own, so the drain blocked forever and the process needed kill -9.
  • Also handle SIGTERM: sandbox-agent daemon stop already sends it, and it previously fell through to the default action - an instant terminate that skipped shutdown_servers cleanup (opencode sidecar, ACP runtimes) entirely.
  • Bound the drain: after the first signal and cleanup, a spawned watchdog exits the process after a 3s grace window, or immediately on a second SIGINT/SIGTERM.

Verification (live, darwin/arm64)

Reproduced on unpatched build: server + sleep 300 process + open logs?follow=true SSE → SIGINT → still running at 10s; exits only once the SSE connection closed.

Patched build:

  • SIGINT, no streams: exits immediately
  • SIGINT with open SSE stream: drains, force-exits inside the 3s bound
  • SIGTERM: graceful cleanup then exit (previously skipped cleanup)
  • second signal during drain: immediate exit

cargo test -p sandbox-agent --lib: 22 passed. cargo fmt --check clean, cargo clippy clean (one pre-existing warning unrelated to this change).

… open streams

with_graceful_shutdown waits for in-flight requests to finish. Long-lived
streams (process log follow SSE, ACP event feeds) never complete on their
own, so Ctrl+C left the server running until kill -9.

Listen for SIGTERM alongside SIGINT (daemon stop already sends it, and it
previously bypassed cleanup entirely), then bound the drain: a second
signal or a 3s timeout exits the process.

Fixes #6
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@wtfsayo wtfsayo closed this by deleting the head repository Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(opencode): server blocks ctrl+c from shutting down gracefully

1 participant