authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-06-11 18:39:25-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-06-12 01:39:25+00:00
log1ea17026eedf634d208e219cbf78da7d4abe17de
tree644607f6290fb1779140b4f13dbdca6c7d25758d
parent649f4328eacff110e3a6c11457be3d43be0d1e60
signature Signed by PGP key B5690EEEBB952194

[codex] fix slow websocket shutdown (#2869)

Co-authored-by: Julius Marminge <julius@macmini.local>

1 files changed, 8 insertions(+), 0 deletions(-)

apps/server/src/server.ts+8
...@@ -87,6 +87,12 @@ import * as NetService from "@t3tools/shared/Net";...@@ -87,6 +87,12 @@ import * as NetService from "@t3tools/shared/Net";
87import * as RelayClient from "@t3tools/shared/relayClient";87import * as RelayClient from "@t3tools/shared/relayClient";
88import { disableTailscaleServe, ensureTailscaleServe } from "@t3tools/tailscale";88import { 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.
94const HTTP_PREEMPTIVE_SHUTDOWN_GRACE_MS = 0;
95
90const PtyAdapterLive = Layer.unwrap(96const PtyAdapterLive = Layer.unwrap(
91 Effect.gen(function* () {97 Effect.gen(function* () {
92 if (typeof Bun !== "undefined") {98 if (typeof Bun !== "undefined") {
...@@ -116,6 +122,7 @@ const HttpServerLive = Layer.unwrap(...@@ -116,6 +122,7 @@ const HttpServerLive = Layer.unwrap(
116 return BunHttpServer.layer({122 return BunHttpServer.layer({
117 port: config.port,123 port: config.port,
118 ...(config.host ? { hostname: config.host } : {}),124 ...(config.host ? { hostname: config.host } : {}),
125 gracefulShutdownTimeout: HTTP_PREEMPTIVE_SHUTDOWN_GRACE_MS,
119 });126 });
120 } else {127 } else {
121 const [NodeHttpServer, NodeHttp] = yield* Effect.all([128 const [NodeHttpServer, NodeHttp] = yield* Effect.all([
...@@ -125,6 +132,7 @@ const HttpServerLive = Layer.unwrap(...@@ -125,6 +132,7 @@ const HttpServerLive = Layer.unwrap(
125 return NodeHttpServer.layer(NodeHttp.createServer, {132 return NodeHttpServer.layer(NodeHttp.createServer, {
126 host: config.host,133 host: config.host,
127 port: config.port,134 port: config.port,
135 gracefulShutdownTimeout: HTTP_PREEMPTIVE_SHUTDOWN_GRACE_MS,
128 });136 });
129 }137 }
130 }),138 }),