DEV Community

Cover image for Nginx reverse proxy dropping WebSocket check-in events under burst load in Docker Compose
Habeeb
Habeeb

Posted on

Nginx reverse proxy dropping WebSocket check-in events under burst load in Docker Compose

Hi everyone,

We're running an on-prem microservice stack on Debian 12 (Docker Engine 26.1, kernel 6.1.0-21-amd64) behind an Nginx reverse proxy to handle front-desk reception kiosks and badge printers.

As part of deploying an on-prem visitor management system across our main lobby terminals, each kiosk maintains a persistent WebSocket connection (wss://) to a Node.js event gateway backed by Redis Pub/Sub for instant badge-print triggers and host notifications.

Expected Behavior

During morning check-in bursts (around 40–60 concurrent badge scans per minute), WebSocket connections should stay persistent and route events cleanly through Nginx to the upstream Node container.

Actual Behavior

Under burst load, kiosks randomly disconnect with code 1006 and fail to receive print-job ACKs for ~15–20 seconds before reconnecting.

Relevant snippet from /var/log/nginx/error.log:

text

2026/11/25 08:42:11 [error] 29#29: *1482 upstream prematurely closed connection while reading response header from upstream, client: 10.20.4.31, server: vms-gw.internal, request: "GET /ws/kiosk HTTP/1.1", upstream: "http://172.19.0.4:4000/ws/kiosk"
2026/11/25 08:42:11 [warn] 29#29: *1485 an upstream response is buffered to a temporary file /var/cache/nginx/proxy_temp/4/00/0000000004 while reading upstream

Current nginx.conf location block:

nginx
location /ws/ {
proxy_pass http://ws_gateway:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_read_timeout 60s;
}

What We've Tried

  1. Increased proxy_read_timeout from 60s to 300s (disconnects still happen right when Redis Pub/Sub fans out payloads).
  2. Verified container memory/CPU limits (docker stats shows < 35% utilization on both nginx and ws_gateway).
  3. Checked sysctl net.core.somaxconn on the host (currently 4096).

Has anyone hit upstream prematurely closed connection on Nginx WebSocket upgrades when proxy_buffering isn't explicitly disabled, or could Redis Pub/Sub backpressure in the Node worker be starving the event loop long enough for Nginx to drop the socket?

Top comments (0)