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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Fix a Node.js connection timeout by first identifying whether the stalled connection is inbound (a client connecting to your Node HTTP server) or outbound (your app connecting to another service). Inbound behavior is controlled mainly by keepAliveTimeout, headersTimeout, and timeout. Outbound failures such as ETIMEDOUT usually require checking DNS, routing, firewalls, and the timeout settings of the HTTP client or database driver. Once you know which side is timing out, set compatible values, restart the process, and verify the result under the same proxy or load-balancer path used in production.

Start by locating the timeout

A timeout is not one single Node.js error. The useful first question is: which socket is waiting, and which component owns it?

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Symptom Likely side What to inspect first
ETIMEDOUT while calling an API, database, or queue Outbound client connection Destination hostname and port, DNS, routes, firewall rules, security groups, and the client library’s connect timeout
Clients receive HTTP 408 from your Node server Inbound server connection server.headersTimeout and server.timeout
502 or intermittent connection resets behind a proxy or load balancer Inbound keep-alive mismatch Node’s keepAliveTimeout compared with the proxy’s idle timeout
A request hangs while the handler is doing work Application or upstream operation Handler-level deadline, upstream timeout, event-loop blocking, and whether the request is actually aborted

Record the exact error, URL or destination, HTTP status (if any), elapsed time, Node.js version, and whether the request passed through a reverse proxy. A timeout that occurs at a repeatable number of milliseconds often points to a configured deadline; a variable delay can indicate packet loss, overloaded dependencies, DNS, or event-loop stalls.

Understand Node’s inbound timeout settings

These properties belong to the HTTP or HTTPS server created by Node. They govern how the server treats connections accepted by your application; they do not set the connect deadline for an API call made by your application.

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application:Upgraded attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Warranty & Support: Our Electric air duster comes with 5 years warranty and 24/7 customer service. During this period, if you have any questions,pls kindly feel free to contact us.

server.keepAliveTimeout

keepAliveTimeout is the amount of time Node waits for additional data on an idle, persistent HTTP connection after it has finished responding. The Node.js HTTPS documentation lists a default of 5,000 ms. Node combines this value with an internal buffer when setting the socket timeout; the buffer is intended to reduce ECONNRESET errors when a peer closes at nearly the same time.

A reverse proxy or load balancer can close an idle connection before Node does. If the proxy advertises a 60-second idle timeout while Node closes keep-alive sockets after five seconds, clients may lose connection reuse and see resets or intermittent 502 responses. If Node closes later than the proxy, the proxy can retain a socket that Node has already ended. Align the values with the component that should close first, and test the complete path rather than only localhost.

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

server.headersTimeout

headersTimeout limits how long Node waits for complete request headers. The current HTTPS documentation lists a default of 60,000 ms. In the Node 10.14.0 line, the HTTP documentation listed a default of 40,000 ms, so do not assume a value from a different Node release applies to your process.

Guidance commonly places headersTimeout slightly above keepAliveTimeout. The header deadline must not be shorter than the period you intentionally allow a persistent connection to remain available. A client that sends headers too slowly can therefore receive a 408 response when this limit is exceeded.

server.timeout

server.timeout is the socket inactivity timeout. It applies when no data is being transferred, including periods in which a request handler or an upstream operation leaves the socket idle. Its default changed from 120 seconds to 0 (no automatic timeout) in Node.js v13.0.0. A value of zero can leave idle connections open indefinitely, which may consume file descriptors and memory if clients disappear without closing cleanly.

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth

Setting a finite value is usually safer for public services, but choose it around the slowest legitimate operation and your proxy’s limits. A server timeout is not a replacement for a deadline around a database or HTTP call; an application can still wait on a dependency while holding resources unless that dependency has its own cancellation or timeout.

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

What a server-side timeout looks like

When headersTimeout or timeout is exceeded, Node can send an HTTP 408 Request Timeout and then terminate the connection. The exact visible symptom depends on whether headers were received, whether a response had started, and whether a proxy generated its own error first.

Inspect the values your running process actually uses

Do not diagnose from a blog post’s defaults. Print the values after your server is created and record the Node version reported by the same process manager or container that serves traffic.

const http = require('node:http');

const server = http.createServer((req, res) => {
  res.end('ok');
});

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

server.listen(process.env.PORT || 3000);

If a framework creates the server for you, obtain the underlying server object or configure the framework’s documented server options. Verify that a later startup module is not overwriting your values. In a clustered deployment, apply the same configuration to every worker.

Choose compatible values behind a load balancer

Suppose your load balancer has a 60-second idle timeout. One documented example sets Node’s keepAliveTimeout to about 65,000 ms and headersTimeout to about 66,000 ms. These are illustrative values, not universal requirements: the correct numbers depend on the proxy, network path, traffic pattern, and Node version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.
  1. Find the idle timeout on every hop: CDN, ingress, reverse proxy, service mesh, and load balancer.
  2. Decide which hop should close an idle keep-alive connection first. Avoid having two components race to close the same socket.
  3. Set keepAliveTimeout to a value compatible with that decision.
  4. Keep headersTimeout above the keep-alive value and high enough for legitimate header transmission.
  5. Set a finite server.timeout if your service must reclaim abandoned sockets.
  6. Restart all workers, then exercise a connection through the real proxy path and inspect access logs for 408, 502, reset, and upstream-timeout events.
const http = require('node:http');

const server = http.createServer(requestHandler);
server.keepAliveTimeout = 65000;
server.headersTimeout = 66000;
server.timeout = 120000; // choose for your workload; this is an example
server.listen(3000);

Do not copy these numbers blindly. A 120-second socket timeout may be inappropriate for a low-latency API, while a long-running export endpoint may need a separate application deadline and a proxy configuration that permits it.

Fix outbound connection timeouts

An outbound timeout occurs while your Node process is acting as a client. The destination may be an HTTPS API, database, cache, message broker, or another service in your network. The general ETIMEDOUT diagnosis is not tied to the inbound server properties above.

Check the destination from the same runtime environment

  1. Resolve the hostname from the container, VM, or pod running Node, not only from your laptop.
  2. Confirm that the destination port is reachable through security groups, network policies, firewalls, and egress controls.
  3. Check whether the hostname resolves to an IPv6 address that your environment cannot route. Test the address family your client selects.
  4. Verify TLS requirements, proxy variables, and service discovery records.
  5. Compare the observed delay with the client library’s connect and overall request deadlines.

For a basic TCP check, use the networking tools approved in your environment, such as nc -vz host.example 443. Use curl -v --connect-timeout 5 https://host.example/health for an HTTPS endpoint when policy permits. These commands distinguish a network connection problem from an application response problem; they do not prove that every request route is healthy.

Set a connect deadline and an overall deadline

Client libraries differ. Some expose separate DNS, TCP-connect, TLS-handshake, and response-body limits; others expose only one request timeout. Read the API for the exact library version in your application. A timeout that starts only after a socket is connected will not protect the connect phase.

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

With Node’s built-in fetch, an AbortSignal can provide an overall deadline:

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), 10000);

try {
  const response = await fetch('https://api.example.test/data', {
    signal: controller.signal
  });
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
  const data = await response.json();
} finally {
  clearTimeout(timer);
}

This example limits the whole fetch operation. It does not by itself tell you whether DNS, TCP, TLS, or response processing consumed the time. Add phase-specific instrumentation when you need that distinction.

Understand the http.Agent and request timeout caveats

An http.Agent timeout applies after the socket connects, so it does not necessarily cover the initial connect phase. Likewise, a ClientRequest timeout event signals socket inactivity; it does not automatically cancel every underlying operation. Abort or destroy the request explicitly, and ensure your promise rejects so the handler does not continue waiting.

const req = require('node:https').request(options, (res) => {
  // consume or destroy the response as appropriate
});

req.setTimeout(10000, () => {
  req.destroy(new Error('upstream socket idle timeout'));
});
req.on('error', next);
req.end();

Use the timeout event for a deliberate cancellation path, not as a guarantee that the remote server stopped work. If the upstream operation is not idempotent, decide whether a retry could duplicate it.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Separate slow application work from a dead connection

A request can appear to time out even when the network is healthy. Common causes include synchronous CPU work blocking the event loop, an exhausted database pool, a promise that never settles, or an upstream call with no deadline. Log timestamps around each phase:

  • request accepted;
  • DNS or service-discovery lookup started and finished;
  • socket connected;
  • TLS handshake completed;
  • upstream request sent;
  • first response byte received;
  • handler completed and response ended.

Use a request ID to correlate the Node access log, dependency log, and proxy log. If the event loop is blocked, socket timers cannot run on schedule. Measure event-loop delay with your monitoring stack and inspect synchronous parsing, compression, regular expressions, and large JSON transformations.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.

Recognize proxy and load-balancer failure modes

502 after an idle period

A 502 often means the proxy could not use its connection to Node, not that Node generated a 502. Compare idle settings and connection reuse. If the proxy reuses a socket that Node has already closed, enable correct keep-alive handling, update the proxy’s pool settings, or choose a server keep-alive value that leaves the intended owner of the connection in control.

408 from Node, 408 from the proxy, or a client-side timeout

Inspect the response headers and each hop’s logs. Node’s header or socket deadline can produce a 408 followed by termination, while a proxy may return its own 408 before the request reaches Node. A browser or SDK may simply report a timeout without receiving an HTTP response. Treat these as different incidents until logs prove otherwise.

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

Streaming and long-polling endpoints

For server-sent events, downloads, uploads, and long polling, a socket may be intentionally open while little data is exchanged. Configure an appropriate heartbeat or chunk cadence, and set timeouts at the route and proxy level to match the protocol. Do not globally disable timeouts merely to make one streaming endpoint work; isolate its policy and monitor open connections.

A repeatable troubleshooting procedure

  1. Capture the failure. Save the exact error text, status code, destination, elapsed time, request method, and Node version.
  2. Classify direction. Decide whether a client is connecting to Node or Node is connecting outward.
  3. Reproduce locally. Test the handler or outbound call without the proxy, then through the same proxy and load balancer used in production.
  4. Print effective configuration. Record keepAliveTimeout, headersTimeout, timeout, agent settings, and framework overrides.
  5. Test reachability. From the serving runtime, check DNS, route, port access, TLS, and any required proxy.
  6. Find the phase that consumed time. Add timing logs or tracing around connect, headers, first byte, and body completion.
  7. Set explicit deadlines. Configure a connect limit where supported, an overall request deadline, and a deliberate server socket policy.
  8. Restart and verify. Configuration changes do not affect already-running workers until they reload. Confirm every worker reports the new values.
  9. Exercise failure paths. Test an unreachable host, a slow header sender, a delayed upstream, and an idle keep-alive connection in a non-production environment.

Common fixes that make the problem worse

  • Raising every timeout. This can hide a failing dependency and increase concurrent sockets until the process runs out of descriptors or memory.
  • Setting server.timeout = 0 without capacity planning. No automatic socket timeout means abandoned connections can remain open indefinitely.
  • Changing only Node. A proxy, ingress, or cloud load balancer can still enforce a shorter deadline.
  • Assuming one version’s defaults. The defaults for headersTimeout and server.timeout vary by Node release; inspect the version you deploy.
  • Handling a timeout event but not aborting. The request may continue in the background and consume a socket or pool slot.
  • Retrying non-idempotent operations automatically. A delayed response may mean the server completed the operation even though the client timed out.
  • Testing only from a developer laptop. Network policy, DNS, and IPv6 behavior can differ completely inside a container or private subnet.

Production checklist

  • Node version and effective timeout values are recorded at startup.
  • Inbound keep-alive, header, and inactivity policies are documented beside proxy and load-balancer limits.
  • Every outbound dependency has an explicit connect or overall deadline appropriate to its protocol.
  • Timeouts abort requests and release response bodies, sockets, and pool slots.
  • Logs distinguish DNS, connect, TLS, time-to-first-byte, and body-read failures where the client supports it.
  • 408, 502, 504, ETIMEDOUT, ECONNRESET, open sockets, and event-loop delay are monitored.
  • Slow-client, delayed-upstream, unreachable-host, and proxy-idle tests run before changing production values.

Bottom line: set the deadline at the layer that owns the wait

Use Node’s server properties for connections arriving at your app, and use the outbound client’s cancellation and connect controls for connections your app initiates. Verify version-specific defaults, make proxy idle limits compatible, keep headersTimeout above the intended keep-alive period, and avoid unlimited sockets unless the workload and capacity model justify them. The fastest reliable fix is the one that identifies the stalled phase first, then changes only the responsible layer.

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.