ERR_HTTP_REQUEST_TIMEOUT
Node.jsERRORNotableHTTPHIGH confidence

HTTP request timed out before completing

Production Risk

Can affect legitimate users with slow connections; tune the timeout carefully.

What this means

Thrown when an incoming HTTP request body has not been fully received within the servers configured requestTimeout period. The server automatically destroys the socket and emits this error. It is primarily a server-side protection against slow-loris style attacks or very slow clients.

Why it happens
  1. 1Client is uploading a large body slower than the server timeout allows
  2. 2Network congestion causing the request body to arrive too slowly
  3. 3The server requestTimeout option is set too aggressively short
How to reproduce

Triggered by the HTTP server internally when requestTimeout elapses before the full request is received.

trigger — this will error
trigger — this will error
const http = require('http');
const server = http.createServer({ requestTimeout: 1000 }, (req, res) => {
  // slow client never finishes sending body
  res.end('ok');
});
server.listen(3000);

expected output

Error [ERR_HTTP_REQUEST_TIMEOUT]: Request timeout

Fix 1

Increase requestTimeout for endpoints with large uploads

WHEN When legitimate clients need more time to upload

Increase requestTimeout for endpoints with large uploads
const server = http.createServer(
  { requestTimeout: 30000 }, // 30 seconds
  handler
);

Why this works

A longer timeout accommodates slower clients while still protecting against indefinite hangs.

Fix 2

Handle the timeout event and return a 408 response

WHEN When you want to respond gracefully instead of dropping the connection

Handle the timeout event and return a 408 response
server.on('timeout', (socket) => {
  socket.end('HTTP/1.1 408 Request Timeout\r\n\r\n');
});

Why this works

Sending a proper 408 response before closing the socket gives the client a meaningful error code.

Code examples
Triggerjs
const http = require('http');
const server = http.createServer({ requestTimeout: 1000 }, (req, res) => {
  // slow client never finishes sending body
  res.end('ok');
});
server.listen(3000);  // this triggers ERR_HTTP_REQUEST_TIMEOUT
Handle in try/catchjs
try {
  // operation that may throw ERR_HTTP_REQUEST_TIMEOUT
  riskyOperation()
} catch (err) {
  if (err.code === 'ERR_HTTP_REQUEST_TIMEOUT') {
    console.error('ERR_HTTP_REQUEST_TIMEOUT:', err.message)
  } else {
    throw err
  }
}
Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_http_request_timeout(...args) {
  // validate args here
  return performOperation(...args)
}
What not to do

Set requestTimeout to 0 (disabled) in public-facing servers

Disabling the timeout exposes the server to slow-loris DoS attacks.

Sources
Official documentation ↗

Node.js Error Codes Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Node.js errors