Skip to content

Commit 4af25fc

Browse files
authored
fix(server): set keep-alive and header timeouts (#4925)
<!-- Describe the problem and your solution --> <!-- Issue ticket number and link (if applicable) --> <!-- Testing instructions (skip if just adding/editing providers) --> <!-- Summary by @propel-code-bot --> --- **Set HTTP keep-alive & header timeouts via env var** Adds explicit timeout management to the HTTP server to reduce the risk of long-lived idle sockets and header stalls. The change introduces a new configurable environment variable so operators can tune the timeout without code changes. <details> <summary><strong>Key Changes</strong></summary> • Set `server.keepAliveTimeout` from `envs.NANGO_SERVER_KEEP_ALIVE_TIMEOUT` in `packages/server/lib/server.ts` • Set `server.headersTimeout` to `envs.NANGO_SERVER_KEEP_ALIVE_TIMEOUT + 1000` to satisfy Node.js requirement that it exceeds keep-alive timeout • Declare new env schema key `NANGO_SERVER_KEEP_ALIVE_TIMEOUT` with default `61_000` (61 s) in `packages/utils/lib/environment/parse.ts` </details> <details> <summary><strong>Affected Areas</strong></summary> • `packages/server/lib/server.ts` • `packages/utils/lib/environment/parse.ts` </details> --- *This summary was automatically generated by @propel-code-bot*
1 parent a9f92b7 commit 4af25fc

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

packages/server/lib/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ app.use('/', router);
5656

5757
const server = http.createServer(app);
5858

59+
server.keepAliveTimeout = envs.NANGO_SERVER_KEEP_ALIVE_TIMEOUT;
60+
server.headersTimeout = envs.NANGO_SERVER_KEEP_ALIVE_TIMEOUT + 1000; //needs to be longer than the keep alive timeout to avoid premature disconnections
5961
// -------
6062
// Websocket
6163
const wss = new WebSocketServer({ server, path: getWebsocketsPath() });

packages/utils/lib/environment/parse.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const ENVS = z.object({
2121
NANGO_PORT: z.coerce.number().optional().default(3003), // Sync those two ports?
2222
SERVER_PORT: z.coerce.number().optional().default(3003),
2323
NANGO_SERVER_URL: z.url().optional(),
24+
NANGO_SERVER_KEEP_ALIVE_TIMEOUT: z.coerce.number().optional().default(61_000),
2425
DEFAULT_RATE_LIMIT_PER_MIN: z.coerce.number().min(1).optional(),
2526
NANGO_CACHE_ENV_KEYS: z.stringbool().optional().default(false),
2627
NANGO_SERVER_WEBSOCKETS_PATH: z.string().optional(),

0 commit comments

Comments
 (0)