Skip to content

Commit 1ea1702

Browse files
juliusmarmingeJulius Marminge
andauthored
[codex] fix slow websocket shutdown (pingdotgg#2869)
Co-authored-by: Julius Marminge <julius@macmini.local>
1 parent 649f432 commit 1ea1702

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

apps/server/src/server.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ import * as NetService from "@t3tools/shared/Net";
8787
import * as RelayClient from "@t3tools/shared/relayClient";
8888
import { disableTailscaleServe, ensureTailscaleServe } from "@t3tools/tailscale";
8989

90+
// Effect's default preemptive shutdown waits 20s before finalizing request scopes.
91+
// T3's primary transport is long-lived WebSocket RPC, whose Effect scope finalizer
92+
// already closes the websocket gracefully. Do not add an artificial drain before
93+
// those finalizers get a chance to run.
94+
const HTTP_PREEMPTIVE_SHUTDOWN_GRACE_MS = 0;
95+
9096
const PtyAdapterLive = Layer.unwrap(
9197
Effect.gen(function* () {
9298
if (typeof Bun !== "undefined") {
@@ -116,6 +122,7 @@ const HttpServerLive = Layer.unwrap(
116122
return BunHttpServer.layer({
117123
port: config.port,
118124
...(config.host ? { hostname: config.host } : {}),
125+
gracefulShutdownTimeout: HTTP_PREEMPTIVE_SHUTDOWN_GRACE_MS,
119126
});
120127
} else {
121128
const [NodeHttpServer, NodeHttp] = yield* Effect.all([
@@ -125,6 +132,7 @@ const HttpServerLive = Layer.unwrap(
125132
return NodeHttpServer.layer(NodeHttp.createServer, {
126133
host: config.host,
127134
port: config.port,
135+
gracefulShutdownTimeout: HTTP_PREEMPTIVE_SHUTDOWN_GRACE_MS,
128136
});
129137
}
130138
}),

0 commit comments

Comments
 (0)