Menu

Node.js server timeouts: requestTimeout, headersTimeout, keepAliveTimeout
📰

Node.js server timeouts: requestTimeout, headersTimeout, keepAliveTimeout

DEV Community: webdev·ApiTraffic·5 days ago
#YFv1ruUV
#devtowebdev#devto#dev#keepalivetimeout#node
Reading 0:00
15s threshold

Two timeout bugs are common in Node APIs that sit behind a load balancer. The first is a trickle of 502s that never reproduce locally: a few an hour, no matching error in your app logs, more of them after quiet periods. The second is a slow handler that holds a socket open for minutes because nothing told it to stop.

Both come from four settings on http.Server that most apps never touch. This post covers what each one controls, which values fix the 502s behind an AWS Application Load Balancer, and how to check the fix worked.

The four settings on http.Server

From the Node.js HTTP docs :

Setting What it limits Default

requestTimeout Time to receive the entire request from the client 300 s (since Node 18)

headersTimeout Time to receive the complete request headers The lower of requestTimeout and 60 s

keepAliveTimeout Idle time on a kept-alive socket after the last response, before Node destroys it 5 s on older lines; 65 s after nodejs/node#62782

timeout Socket inactivity of any kind 0 (disabled, since…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.