Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ import {
import * as NetService from "@t3tools/shared/Net";
import { disableTailscaleServe, ensureTailscaleServe } from "@t3tools/tailscale";

// Effect's default preemptive shutdown waits 20s before finalizing request scopes.
// T3's primary transport is long-lived WebSocket RPC, whose Effect scope finalizer
// already closes the websocket gracefully. Do not add an artificial drain before
// those finalizers get a chance to run.
const HTTP_PREEMPTIVE_SHUTDOWN_GRACE_MS = 0;

const PtyAdapterLive = Layer.unwrap(
Effect.gen(function* () {
if (typeof Bun !== "undefined") {
Expand All @@ -114,6 +120,7 @@ const HttpServerLive = Layer.unwrap(
return BunHttpServer.layer({
port: config.port,
...(config.host ? { hostname: config.host } : {}),
gracefulShutdownTimeout: HTTP_PREEMPTIVE_SHUTDOWN_GRACE_MS,
});
} else {
const [NodeHttpServer, NodeHttp] = yield* Effect.all([
Expand All @@ -123,6 +130,7 @@ const HttpServerLive = Layer.unwrap(
return NodeHttpServer.layer(NodeHttp.createServer, {
host: config.host,
port: config.port,
gracefulShutdownTimeout: HTTP_PREEMPTIVE_SHUTDOWN_GRACE_MS,
});
}
}),
Expand Down
Loading