net::ERR_CONNECTION_RESET when large file takes longer than a minute

net::ERR_CONNECTION_RESET when large file takes longer than a minute

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

net::ERR_CONNECTION_RESET When Large Files Take Longer Than a Minute

When you are debugging a persistent net::ERR_CONNECTION_RESET that occurs strictly after one minute, your initial instinct is often to check PHP's max_execution_time, Apache's Timeout, or Nginx's proxy_read_timeout. In the scenario described, these settings have already been tuned to 180 seconds, and even a simple script sleeping for 2.5 minutes completes successfully. This discrepancy—where a short-lived idle connection works but a long-running upload fails immediately after the one-minute mark—is almost never about PHP execution time or application logic timeouts.

The root cause here is almost certainly the TCP Keepalive mechanism interacting with an intermediate network device, specifically a Network Link Conditioner (NLC) or a load balancer configured to drop idle connections.

The Illusion of a "Working" Timeout

You mentioned that you set max_execution_time and TimeOut in Apache to 180 seconds. While these prevent the server process from hanging indefinitely, they do not control the behavior of the underlying TCP connection between the client (browser) and the load balancer or gateway.

TCP Keepalive is a feature designed to detect dead connections. By default, many Linux distributions disable this at the kernel level (net.ipv4.tcp_keepalive_time), but cloud environments and managed appliances often enable it with aggressive defaults. If your network path includes a link conditioner or a proxy that enforces strict idle timeouts (often set to 60 seconds by default for security or resource management reasons), the device will close the socket if no data is written for longer than its configured threshold.

Why It Happens Exactly at One Minute

The behavior you are observing aligns perfectly with standard TCP Keepalive intervals found on many load balancers and link conditioners. When you upload a 250MB file over a fast connection, the transfer rate is high enough that the time between packets never exceeds the Keepalive timeout window. The connection appears "alive" constantly.

However, when you artificially slow down the network or run on a slower link, the gap between data packets widens. Once that gap exceeds the device's idle timeout (frequently 60 seconds), the intermediary device sends a RST (Reset) packet to terminate the connection abruptly. The PHP script might still be running and ready to accept the next chunk of data, but the socket has already been severed by the network infrastructure. This explains why sleep scripts work: they generate activity every second or maintain an active session state that bypasses the idle detection logic until the actual resource-intensive processing begins, or simply because your test script isn't triggering the specific upload flow where the packet intervals are largest.

Diagnosing the Intermediary

Since server-side logs show no errors, the crash is happening in the network layer before the request even reaches your PHP application's error handling logic. To confirm this, you can inspect the TCP Keepalive settings on your load balancer or gateway. Common defaults include:

  • Idle Timeout: 60 seconds.
  • Keepalive Interval: 30 or 60 seconds.

If the connection is idle for longer than the configured timeout, the device resets it. This is why upgrading PHP versions or adding more RAM does not resolve the issue; the bottleneck is the network path, not the server resources.

The Solution: Adjusting Keepalive Parameters

To fix this, you need to coordinate the timeouts between your client, your load balancer/gateway, and your application server.

  1. Increase Idle Timeout on the Gateway: If you control the link conditioner or load balancer, increase its idle timeout to match or exceed your expected maximum upload duration plus a buffer (e.g., set it to 300 seconds).
  2. Tune Kernel Keepalive: If the reset originates from the server itself or if the upstream device relies on the downstream device's keepalive settings, ensure the kernel parameters are tuned for long uploads:
    # Set idle time (default is often 7200s, but can be lower)
    sysctl -w net.ipv4.tcp_keepalive_time=300
    
    # Frequency of probes after idle period (default is 7500s total usually)
    sysctl -w net.ipv4.tcp_keepalive_intvl=60
    
    # Number of failed probes before reset (default is 15)
    sysctl -w net.ipv4.tcp_keepalive_probes=9
    
  3. Client-Side Configuration: In some cases, browsers may not support client-side Keepalive adjustments for uploads, but ensuring your server and proxy are configured to tolerate long idle periods is the primary fix.

Conclusion

The net::ERR_CONNECTION_RESET you are encountering is a classic symptom of an intermediate network device enforcing an aggressive idle timeout. When large files are transferred over slow connections, the time between packets exceeds this threshold, causing the device to reset the connection before the upload completes. Tuning the TCP Keepalive and Idle Timeout settings on your load balancer or link conditioner to accommodate your maximum expected upload duration is the correct resolution.

Our network