[codex] fix slow websocket shutdown#2869
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
ApprovabilityVerdict: Approved This is a targeted configuration change that sets the HTTP graceful shutdown timeout to 0ms, fixing slow WebSocket shutdown. The change is well-documented, limited in scope, and the existing WebSocket finalizers still handle graceful closure. You can customize Macroscope's approvability policy. Learn more. |
Summary
0for both Node and Bun server layers./wsconnections instead of waiting through the default 20s pre-finalizer drain.Root Cause
Effect's HTTP server defaults to a 20s preemptive shutdown wait before request scopes are finalized. T3's primary transport is long-lived WebSocket RPC, so shutdown was waiting on active
/wsupgrades before the scoped WebSocket finalizers and provider finalizers could run.Impact
Ctrl-C/server shutdown no longer pauses for the default 20s HTTP preemptive drain while browser WebSocket connections are open. This does not add force-close behavior for provider sessions; it lets Effect's existing scoped finalizers run immediately.
Validation
bun fmtbun lint(passes with existing unrelated warnings)bun typecheckbun run --cwd apps/server test src/server.test.ts/wssockets open exited in ~293ms during investigation.Note
Fix slow WebSocket shutdown by setting
gracefulShutdownTimeoutto 0msSets
gracefulShutdownTimeoutto 0ms on both Bun and Node HTTP server layers in server.ts. Effect already applies its own preemptive shutdown grace period, so an additional timeout was causing WebSocket connections to shut down slowly. Behavioral Change: HTTP servers no longer wait for an extra grace period beyond Effect's default during shutdown.Macroscope summarized 77807c5.
Note
Low Risk
Only affects shutdown timing for the HTTP server layer; no changes to auth, RPC handlers, or connection teardown logic beyond skipping the default preemptive wait.
Overview
Sets
gracefulShutdownTimeoutto0mson both Bun and Node Effect HTTP server layers via a sharedHTTP_PREEMPTIVE_SHUTDOWN_GRACE_MSconstant, with a short comment explaining why.Before: shutdown could sit in Effect’s default ~20s preemptive HTTP drain while
/wsupgrades were still open, delaying request-scope finalizers (including WebSocket teardown).After: that extra drain is skipped so existing scoped WebSocket finalizers run right away; graceful close behavior is unchanged—only the artificial wait is removed.
Reviewed by Cursor Bugbot for commit 77807c5. Bugbot is set up for automated code reviews on this repo. Configure here.