Skip to content

Commit 98d0260

Browse files
committed
feat(webapp): make HTTP keep-alive timeout configurable
Expose the Express server's `keepAliveTimeout` as `HTTP_KEEPALIVE_TIMEOUT_MS` so it can be tuned alongside the upstream load balancer's idle timeout without a redeploy. Default stays at 65s.
1 parent 832cf72 commit 98d0260

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: improvement
4+
---
5+
6+
Make the Express server's `keepAliveTimeout` configurable via `HTTP_KEEPALIVE_TIMEOUT_MS` (defaults to the previous hardcoded 65000 ms).

apps/webapp/server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const ENABLE_CLUSTER = process.env.ENABLE_CLUSTER === "1";
1919
const cpuCount = os.availableParallelism();
2020
const WORKERS =
2121
Number.parseInt(process.env.WEB_CONCURRENCY || process.env.CLUSTER_WORKERS || "", 10) || cpuCount;
22+
// Must be greater than the upstream load balancer's idle timeout to avoid the
23+
// LB pipelining a request onto a connection Node has already closed (→ 502).
24+
const HTTP_KEEPALIVE_TIMEOUT_MS =
25+
Number.parseInt(process.env.HTTP_KEEPALIVE_TIMEOUT_MS || "", 10) || 65 * 1000;
2226

2327
function forkWorkers() {
2428
for (let i = 0; i < WORKERS; i++) {
@@ -200,7 +204,7 @@ if (ENABLE_CLUSTER && cluster.isPrimary) {
200204
}
201205
});
202206

203-
server.keepAliveTimeout = 65 * 1000;
207+
server.keepAliveTimeout = HTTP_KEEPALIVE_TIMEOUT_MS;
204208
// Mitigate against https://github.com/triggerdotdev/trigger.dev/security/dependabot/128
205209
// by not allowing 2000+ headers to be sent and causing a DoS
206210
// headers will instead be limited by the maxHeaderSize

0 commit comments

Comments
 (0)