Skip to content

[codex] fix slow websocket shutdown#2869

Open
juliusmarminge wants to merge 1 commit into
mainfrom
codex/fix-effect-http-shutdown
Open

[codex] fix slow websocket shutdown#2869
juliusmarminge wants to merge 1 commit into
mainfrom
codex/fix-effect-http-shutdown

Conversation

@juliusmarminge
Copy link
Copy Markdown
Member

@juliusmarminge juliusmarminge commented May 30, 2026

Summary

  • Set the Effect HTTP server preemptive graceful shutdown timeout to 0 for both Node and Bun server layers.
  • Keep Effect's scoped WebSocket finalizers responsible for closing long-lived /ws connections 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 /ws upgrades 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 fmt
  • bun lint (passes with existing unrelated warnings)
  • bun typecheck
  • bun run --cwd apps/server test src/server.test.ts
  • Real shutdown probe with authenticated /ws sockets open exited in ~293ms during investigation.

Note

Fix slow WebSocket shutdown by setting gracefulShutdownTimeout to 0ms

Sets gracefulShutdownTimeout to 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 gracefulShutdownTimeout to 0ms on both Bun and Node Effect HTTP server layers via a shared HTTP_PREEMPTIVE_SHUTDOWN_GRACE_MS constant, with a short comment explaining why.

Before: shutdown could sit in Effect’s default ~20s preemptive HTTP drain while /ws upgrades 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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b126866e-5b05-46c1-b84b-441be5265543

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-effect-http-shutdown

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added size:XS 0-9 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels May 30, 2026
@juliusmarminge juliusmarminge marked this pull request as ready for review May 30, 2026 04:46
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented May 30, 2026

Approvability

Verdict: 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant