Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk10 min

How to Fix Connection Timeouts on a Node.js App (Server and Client)

A practical guide to diagnosing and fixing Node.js connection timeouts, including keepAliveTimeout, headersTimeout, server.timeout, outbound ETIMEDOUT errors, load balancer 502s and safe client cancellation.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A Node.js connection timeout has two very different causes: your server may be timing out an incoming connection, or your application may be unable to connect to an upstream service. Identify which direction is failing before changing a setting. For incoming traffic, inspect keepAliveTimeout, headersTimeout, and timeout. For outgoing traffic, check DNS, routing, firewalls, the remote host, and the HTTP client’s connect and request timers.

Start by recording the Node.js version, the exact error and status code, and where the delay occurs (DNS, TCP connect, TLS, request headers, or response body). Then change the smallest relevant timeout, align it with any reverse proxy or load balancer, deploy, and test under the same network conditions that produced the failure.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

First determine which connection is timing out

“Connection timeout” is not one Node.js setting. An HTTP server and an HTTP client use different timers, and a timeout in one direction does not fix a timeout in the other.

What is timing out? Typical evidence Where to investigate
Incoming request to your Node.js server Clients report 408, a proxy reports 502 or 504, or the server closes an apparently idle keep-alive socket server.keepAliveTimeout, server.headersTimeout, server.timeout, and the proxy or load balancer idle timeout
Outgoing request made by your app ETIMEDOUT, ECONNREFUSED, DNS errors, or a request that never reaches the upstream service DNS, routes, firewall rules, security groups, remote service health, and the client library’s connect and request timers
Application work after a connection succeeds The TCP connection is established but the response takes too long, or a socket is closed while a handler is still working Request or socket inactivity settings, upstream latency, event-loop blocking, and proxy response limits

Do not treat an ETIMEDOUT error as proof that server.timeout is too low. ETIMEDOUT generally points to an outbound connection attempt or network path. Conversely, changing an HTTP client’s timeout cannot prevent your own server from returning a 408 to an incoming request.

#1 Best Overall
Sale
TP-Link USB to Ethernet Adapter,Support Nintendo Switch,1Gbps,Plug and Play | Gigabit RJ45 to USB A 3.0 Network Adapter, Foldable & Portable Design, Compatible w/ Windows, macOS, & Linux(UE306)
  • 𝐇𝐢𝐠𝐡-𝐒𝐩𝐞𝐞𝐝 𝐔𝐒𝐁 𝐄𝐭𝐡𝐞𝐫𝐧𝐞𝐭 𝐀𝐝𝐚𝐩𝐭𝐞𝐫 - UE306 is a USB 3.0 Type-A to RJ45 Ethernet adapter that adds a reliable wired network port to your laptop, tablet, or Ultrabook. It delivers fast and stable 10/100/1000 Mbps wired connections to your computer or tablet via a router or network switch, making it ideal for file transfers, HD video streaming, online gaming, and video conferencing.
  • 𝐔𝐒𝐁 𝟑.𝟎 𝐟𝐨𝐫 𝐅𝐚𝐬𝐭𝐞𝐫, 𝐌𝐨𝐫𝐞 𝐒𝐭𝐚𝐛𝐥𝐞 𝐃𝐚𝐭𝐚 𝐓𝐫𝐚𝐧𝐬𝐟𝐞𝐫𝐬- Powered via USB 3.0, this adapter provides high-speed Gigabit Ethernet without the need for external power(10/100/1000Mbps). Backward compatible with USB 2.0/1.1, it ensures reliable performance across a wide range of devices.
  • 𝐒𝐮𝐩𝐩𝐨𝐫𝐭𝐬 𝐍𝐢𝐧𝐭𝐞𝐧𝐝𝐨 𝐒𝐰𝐢𝐭𝐜𝐡- Easily connect your Nintendo Switch to a wired network for faster downloads and a more stable online gaming experience compared to Wi-Fi.
  • 𝐏𝐥𝐮𝐠 𝐚𝐧𝐝 𝐏𝐥𝐚𝐲- No driver required for Nintendo Switch, Windows 11/10/8.1/8, and Linux. Simply connect and enjoy instant wired internet access without complicated setup.
  • 𝐁𝐫𝐨𝐚𝐝 𝐃𝐞𝐯𝐢𝐜𝐞 𝐂𝐨𝐦𝐩𝐚𝐭𝐢𝐛𝐢𝐥𝐢𝐭𝐲- Supports Nintendo Switch, PCs, laptops, Ultrabooks, tablets, and other USB-powered web devices; works with network equipment including modems, routers, and switches.

Capture the failure before changing values

Log the operation, destination, elapsed time, error code, and response status. Include a correlation ID so that a client request, an outbound call, and a reverse-proxy log can be matched. A useful minimum is:

  • Node.js version from process.version.
  • Whether the operation is inbound or outbound.
  • Hostname and port (without credentials or sensitive query data).
  • Elapsed milliseconds until failure.
  • Error name, code, syscall, and address fields when present.
  • HTTP status, if any bytes were received.
console.error({
  node: process.version,
  operation: 'upstream-request',
  elapsedMs,
  error: {
    name: err.name,
    code: err.code,
    syscall: err.syscall,
    address: err.address,
    port: err.port,
    message: err.message
  }
});

A status code means an HTTP peer answered; a low-level error such as ETIMEDOUT or ECONNRESET may occur before an HTTP response exists.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How Node.js server timeout settings work

These properties apply to an HTTP or HTTPS server handling incoming sockets. Their defaults are version-dependent, so verify the exact Node.js release in production rather than copying a value from a different version.

server.keepAliveTimeout

This is the period Node waits for additional data on an idle keep-alive socket after it has finished serving a response. The Node.js HTTPS documentation lists a 5,000 ms default. Node combines the configured value with an internal buffer when setting the socket timeout; that buffer is intended to reduce avoidable ECONNRESET errors.

A load balancer may keep an idle connection open longer than Node does. In that case, the balancer can reuse a socket that Node has already closed, producing intermittent 502 responses or reset connections. Set the Node value longer than the balancer’s idle period when the balancer is expected to own that idle limit.

Rank #2
Amazon Basics USB 3.0 to 10/100/1000 Gigabit Ethernet Internet Adapter, Compatible with Windows and macOS, Black
  • Connects a USB 3.0 device (computer/laptop) to a router, modem, or network switch to deliver Gigabit Ethernet to your network connection. Does not support Smart TV or gaming consoles (e.g.Nintendo Switch).
  • Supported features include Wake-on-LAN function, Green Ethernet & IEEE 802.3az-2010 (Energy Efficient Ethernet)
  • Supports IPv4/IPv6 pack Checksum Offload Engine (COE) to reduce Cental Processing Unit (CPU) loading
  • Compatible with Windows 8.1 or higher, Mac OS

server.headersTimeout

This limits how long Node waits for complete request headers. The current Node.js HTTPS documentation lists a 60,000 ms default. In the Node 10.14.x documentation, the default was 40,000 ms; that release-specific value demonstrates why a version check matters.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep this value above keepAliveTimeout when you tune both. A common example for a load balancer with a 60-second idle timeout is keepAliveTimeout = 65,000 and headersTimeout = 66,000. Those are alignment examples, not universal recommendations.

server.timeout

This is the inactivity timeout for an established socket. Its default changed from 120 seconds to 0 (no timeout) in Node.js v13.0.0. A value of 0 can leave inactive connections open indefinitely, so it should be a deliberate capacity decision rather than an automatic “fix.” Long-lived sockets consume file descriptors and memory, and they can hide stalled clients.

When a headers or socket inactivity limit is exceeded, Node commonly sends a 408 Request Timeout response and then terminates the connection. A proxy may translate the same event into a 502 or 504, so inspect both Node and proxy logs.

Step-by-step: fix an incoming connection timeout

  1. Confirm the running version. Print process.version at startup and check the version used by the deployed process, not only the one installed on a workstation.
  2. Inspect effective values. Log server.keepAliveTimeout, server.headersTimeout, and server.timeout after the server is created. Configuration libraries or framework defaults may overwrite values later.
  3. Compare every hop. Record the idle and request-header limits on the reverse proxy, API gateway, ingress controller, and load balancer. The shortest idle limit normally wins.
  4. Set an intentional baseline. Configure values on the actual http.Server or https.Server, then keep the header limit slightly above the keep-alive limit.
  5. Deploy and observe. Watch 408, 502, 504, ECONNRESET, open-connection counts, and latency after the change. A higher timeout that merely accumulates stuck sockets is not a successful fix.
const http = require('node:http');

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'content-type': 'text/plain' });
  res.end('ok');
});

// Example only: align these with the proxy or load balancer.
server.keepAliveTimeout = 65_000;
server.headersTimeout = 66_000;
server.timeout = 120_000;

server.listen(3000, () => {
  console.log({
    node: process.version,
    keepAliveTimeout: server.keepAliveTimeout,
    headersTimeout: server.headersTimeout,
    timeout: server.timeout
  });
});

Use the smallest value that accommodates legitimate clients. If uploads or request headers can legitimately take longer, increase the relevant limit and enforce an application-level maximum size and authentication policy. Do not raise every timeout simply because one request is slow.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
USB A/C to Ethernet Adapter, 3xUSB3.0 and 1000M RJ45 Network hub for laptop | Plug & play 4-in-1 USB C Hub, Gigabit LAN for Mac/Chrome/XPS & USB-C phones/iPad, 3 USB-A ports for mouse/keyboard/USB fan.
  • [Expansion Ports] The USB C to Ethernet Adapter expands the device to three USB 3.0 ports and one Gigabit Ethernet port. Provides you more peripheral ports while maintaining a stable network connection, plug and play, no driver required.
  • [Gigabit Network Port] ALL-LUCKY USB Ethernet Adapter transmission rate up to 1000Mbps, also compatible with 10/100Mbps bandwidth. It allows you to enjoy a smooth and stable network connection and avoid too much lag. (Note: To reach 1Gbps, please use CAT6 or above Ethernet cable connection)
  • [Convertible Connector]This usb hub with ethernet not only has USB-A connector, but also can be converted to USB-C connector, so that you can easily convert the connector according to the device port, improve the convenience of use.
  • [High-Speed Data Transfer] The usb to ethernet adapter adopts USB 3.0 transmission technology, supports up to 5Gbps transmission rate, and is compatible with USB 2.0(480Gbps),USB 1.0(12Mbps), easily transfer video, files and other data for you in seconds. (Note: Maximum output current is 900mA, does not support charging devices.)
  • [Widely Compatible]The usb c ethernet adapter for iMac, MacBook Pro, iPad Pro, XPS and many other devices. Compatible with Windows 11/10/8.1/8, Mac OS, iPad OS, Chrome OS.(Note: Driver is required on Win 7) It can be used in office, school, library and other occasions, compact and portable, easy to carry around.

When a load balancer returns 502

Check whether the balancer’s idle timeout is longer than Node’s keep-alive timeout. If it is, the balancer can send a new request on a socket Node has discarded. Set Node’s keep-alive timeout above the balancer’s idle value, and set headersTimeout above the new keep-alive value. The 65,000/66,000 ms example for a 60-second balancer is a practical illustration.

Also check the opposite mismatch: if the balancer closes idle sockets sooner than Node expects, clients may see resets even though Node’s values look generous. The fix is to document one idle-timeout contract for every hop and apply it consistently.

Fixing outbound timeouts and ETIMEDOUT

When your application is the client, begin with the destination and the network path. A connect timeout means the TCP (or, for HTTPS, TCP/TLS) connection did not complete within the client’s limit; it is not the same as waiting too long for an already-established HTTP response.

Check the network path in order

  1. Resolve the hostname. Verify that the runtime resolves the same name and address family as the failing environment. A container, private subnet, or IPv6 preference can produce different results from a developer laptop.
  2. Verify routing and policy. Check outbound firewall rules, cloud security groups, network ACLs, service-mesh policy, and egress proxies. A dropped packet often appears as a timeout rather than a clear rejection.
  3. Confirm the destination port. Make sure the service is listening on the port your code uses and that an intermediate firewall allows it.
  4. Check the remote service. Review its health, rate limits, connection limits, and allowlists. A service that is overloaded or blocking the caller may never complete a handshake.
  5. Compare environments. Run a connectivity test from the same host, container, or pod as Node. Testing from a workstation does not prove that production can reach the endpoint.

Do not log full authorization headers or request bodies while diagnosing. Hostnames, ports, timing, and error metadata are usually enough.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Separate connect, response, and total-operation limits

A robust client uses distinct budgets:

  • Connect budget: time to establish TCP and, for HTTPS, complete TLS.
  • Response-header budget: time to receive the upstream response headers after the request is sent.
  • Body or inactivity budget: maximum gap between bytes while receiving a response.
  • Total-operation budget: an upper bound covering retries and all phases.

The exact options differ by HTTP client. In Node’s core APIs, an agent timeout applies after the socket connects, so it does not cover the connect phase. A ClientRequest timeout event signals socket inactivity; it does not automatically abort the request. Destroy or abort the request in the timeout handler.

Rank #4
Sale
Anker USB C to Ethernet Adapter, Portable 1 Gbps Network Hub | Aluminum, Compact, 10/100/1000Mbps, for MacBook Pro, iPad Pro, ChromeBook, XPS, Galaxy and More
  • The Anker Advantage: Join the 65 million+ powered by our leading technology.
  • Instant Internet: Connect to the internet instantly from virtually any USB-C 3.0 device, and enjoy stable connection speeds of up to 1 Gbps.
  • Lightweight and Compact: The space-saving and portable design measures just over half an inch thick and weighs about the same as a AA battery.
  • Premium Build: Features a sleek aluminum exterior and braided-nylon cable to complement the design of high-end devices.
  • What You Get: PowerExpand USB-C to Gigabit Ethernet Adapter, welcome guide, 18-month worry-free warranty, and friendly customer service.
const https = require('node:https');

function getWithTimeout(url, timeoutMs) {
  return new Promise((resolve, reject) => {
    const req = https.get(url, (res) => {
      const chunks = [];
      res.on('data', (chunk) => chunks.push(chunk));
      res.on('end', () => {
        resolve({
          statusCode: res.statusCode,
          body: Buffer.concat(chunks).toString('utf8')
        });
      });
    });

    // This callback reports inactivity; explicitly destroy the request.
    req.setTimeout(timeoutMs, () => {
      req.destroy(new Error(`upstream inactivity timeout after ${timeoutMs} ms`));
    });

    req.on('error', reject);
  });
}

For a strict connect budget, use a client option that explicitly supports connect timeouts. If your chosen API does not, start a timer when creating the request and clear it only when the socket has connected (and, for TLS, when the secure connection is established). Destroy the request when that timer expires. Do not leave a timer running after success, or it can terminate a healthy long response.

Retry only when it is safe

A timed-out request may have reached the server even if your client received no response. Automatically retrying a non-idempotent operation can create duplicates. Restrict retries to operations designed to be repeated, use an idempotency key where the API supports one, and apply bounded exponential backoff with jitter. A retry policy cannot repair a blocked route or a consistently unreachable host.

Diagnose by the symptom

Symptom Likely phase Useful next check
ETIMEDOUT before any HTTP status DNS, TCP connect, TLS, or a dropped network path Resolve the name and test the destination from the same runtime environment; inspect egress controls and the client’s connect timer
ECONNREFUSED A host answered but rejected the port Verify the port, listener, service health, and firewall rules
408 from Node Request headers or socket inactivity exceeded a server limit Inspect headersTimeout, timeout, slow clients, and proxy header behavior
502 after an idle period Proxy reused or closed a connection differently from Node Compare load balancer idle timeout with keepAliveTimeout and check reset events
504 from a gateway Gateway’s upstream response budget expired Compare gateway timeout with application processing time and upstream latency
ECONNRESET during reuse of a socket One side closed a keep-alive connection while the other reused it Align idle settings and inspect connection-pool behavior

Instrument the phases instead of guessing

Measure timestamps for request creation, DNS completion, socket assignment, TCP connection, TLS completion, request write, response headers, first body byte, and response end. The events available depend on the client library, but the principle is the same: identify the first phase that exceeds its budget.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • If DNS is slow, investigate resolvers, search domains, and address-family selection.
  • If TCP never connects, investigate routes, firewalls, security groups, and the destination listener.
  • If TCP connects but TLS stalls, inspect certificates, protocol negotiation, proxies, and server capacity.
  • If headers are slow, inspect upstream application latency, database calls, event-loop blocking, and gateway limits.
  • If headers arrive but the body stalls, inspect streaming behavior, backpressure, idle timers, and intermediate proxies.

Correlate these measurements with reverse-proxy access logs and the upstream service’s logs. A timeout recorded at one layer may be the consequence of an earlier layer closing the socket.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose timeout values by architecture

Architecture or workload Configuration approach Risk to watch
Standard API behind a 60-second load balancer Use a keep-alive value above 60 seconds and a headers value slightly above it; 65,000/66,000 ms is an example Higher idle limits increase open sockets if clients disappear
Slow upload from known clients Raise the header or inactivity budget only as needed; enforce body-size and authentication limits separately Slowloris-style clients can consume connections
Long-running job Prefer an asynchronous job API or polling instead of holding an HTTP request open indefinitely Proxy and client limits may still be shorter than Node’s
Internal service-to-service call Set explicit connect, response, inactivity, and total-operation budgets in the client Retries can multiply load and duplicate writes
Streaming or server-sent responses Use an inactivity budget that allows the expected gap between chunks and configure every intermediary accordingly A proxy may terminate a stream even when Node remains healthy

Common fixes that fail

Changing the wrong side

Increasing server.timeout does nothing for an outbound ETIMEDOUT caused by a blocked route. Increasing a client’s request timeout does nothing for a load balancer that closes an idle inbound socket. Always classify the direction first.

Best Value
BENFEI USB 3.0 to Ethernet Adapter, USB C to RJ45 Gigabit LAN (1000Mbps) Network Adapter, Compatible with MacBook/Pro/Air, Surface Pro, Windows 11/10/8/7, Mac OS [Aluminium Shell&Nylon Cable]
  • COMPACT DESIGN - The compact-designed portable BENFEI USB A/C to Ethernet adapter connects your computer or tablet to a router,modem or network switch for network connection. It adds a standard RJ45 port to your Ultrabook, notebook or Macbook Air for file transferring, video conferencing, gaming, and HD video streaming.
  • SUPERIOR STABILITY - Built-in advanced IC chip works as the bridge between RJ45 Ethernet cable and your USB A/C devices. The driver-free installation with native driver support in Chrome, Mac, and Windows OS; The USB A/C Ethernet adapter dongle supports important performance features including Wake-on-Lan (WoL), Full-Duplex (FDX) and Half-Duplex (HDX) Ethernet, Crossover Detection, Backpressure Routing, Auto-Correction (Auto MDIX).
  • INCREDIBLE PERFORMANCE - Supports full 10/100/1000Mbps gigabit ethernet performance over USB A/C's 5Gbps bus, faster and more reliable than most wireless connections. Link and Activity LEDs. USB powered, no external power required. Backward compatible with USB 2.0/1.1.✅ To reach 1Gbps, make sure to use CAT6 & up Ethernet cables.
  • BROAD COMPATIBILITY - The USB A/C-Ethernet adapter is compatible with Windows 11/10/8.1/8/7/Vista/XP, Mac OSX 10.6/10.7/10.8/10.9/10.10/10.11/10.12, Linux kernel 3.x/2.6, Android and Chrome OS.Compatible with IEEE 802.3, IEEE 802.3u and IEEE 802.3ab. Supports IEEE 802.3az (Energy Efficient Ethernet).❌Do Not Support Windows RT. (NOT compatible with Nintendo Switch.)
  • 18 MONTH WARRANTY - Exclusive BENFEI Unconditional 18-month Warranty ensures long-time satisfaction of your purchase; Friendly and easy-to-reach customer service to solve your problems timely.

Setting every value to zero

Disabling timeouts can make a test appear successful while allowing abandoned sockets to accumulate. It also leaves capacity vulnerable to slow or malicious clients. Use finite, workload-specific limits and monitor active connections.

Raising only keepAliveTimeout

If headersTimeout remains lower, Node can still terminate a request while waiting for headers. Keep the relationship between the two values explicit and verify the effective settings after framework initialization.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Assuming defaults are stable

The documented keepAliveTimeout default is 5,000 ms, the current HTTPS documentation lists headersTimeout as 60,000 ms, and Node v10.14.x documented a 40,000 ms header default. The server.timeout default changed from 120 seconds to no timeout in v13.0.0. Pin or record the Node version and review timeout behavior during upgrades.

Handling a timeout event without aborting

In core client APIs, a timeout callback or event is a signal, not necessarily cancellation. Destroy or abort the request, clear associated timers, and ensure the promise or callback settles exactly once. Otherwise timed-out work can continue in the background and consume sockets.

Production checklist

  • Record the Node.js version and effective server timeout values at startup.
  • Label metrics and logs as inbound or outbound.
  • Capture error code, phase, destination, elapsed time, and HTTP status separately.
  • Document idle and response limits for every proxy, gateway, load balancer, and service.
  • Keep headersTimeout above keepAliveTimeout when both are customized.
  • Set an explicit outbound connect timeout; do not assume an agent timeout covers connection establishment.
  • Abort timed-out client requests and clear timers.
  • Retry only idempotent or explicitly deduplicated operations.
  • Load-test slow headers, slow bodies, dropped connections, and long upstream latency.
  • After deployment, watch 408, 502, 504, ETIMEDOUT, ECONNRESET, open sockets, and event-loop delay.

The durable fix is a matched timeout policy, not one large number: identify the failing phase, configure the corresponding Node.js setting or client budget, align every intermediary, and verify the result from the same environment where the timeout occurs.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.