Problem
The JSS server process crashes when a TCP connection is reset by the client (e.g. browser navigation, haproxy health checks, aborted preflight requests). This results in pm2 restarting the process repeatedly (953+ restarts observed) and intermittent 502 Bad Gateway errors for users.
Error log
Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:216:20) {
errno: -104,
code: 'ECONNRESET',
syscall: 'read'
}
Expected behavior
ECONNRESET is normal network noise (clients closing connections early). The server should handle this gracefully without crashing.
Suggested fix
Catch the error at the process level or on the HTTP server socket:
process.on('uncaughtException', (err) => {
if (err.code === 'ECONNRESET') return
console.error('Uncaught exception:', err)
process.exit(1)
})
Or ideally, handle it on the server/socket 'error' event so it never becomes uncaught.
Environment
- JSS v0.0.91
- Node.js on Ubuntu
- Behind haproxy reverse proxy
- pm2 process manager
Problem
The JSS server process crashes when a TCP connection is reset by the client (e.g. browser navigation, haproxy health checks, aborted preflight requests). This results in pm2 restarting the process repeatedly (953+ restarts observed) and intermittent 502 Bad Gateway errors for users.
Error log
Expected behavior
ECONNRESETis normal network noise (clients closing connections early). The server should handle this gracefully without crashing.Suggested fix
Catch the error at the process level or on the HTTP server socket:
Or ideally, handle it on the server/socket
'error'event so it never becomes uncaught.Environment