http-party/node-http-proxy

Node 18 will close proxied websocket connections after ~60 seconds

reey opened this issue · 1 comments

reey commented

With Nodejs 18 another set of http timeouts have been introduced:

  • headersTimeout
  • requestTimeout

see: https://nodejs.org/en/blog/release/v18.0.0/#http-timeouts

These timeouts cause that established websocket connections are closed after roughly 60 seconds.
if you inspect the websocket connection via Wireshark, you see that nodejs just sends:

HTTP/1.1 408 Request Timeout
Connection: close

Through the websocket connection after the timeout.

The simplest workaround to prevent this, is to set both timeouts to zero:

const app = express();
[...]
const server = app.listen(process.env.SERVER_PORT);

// disable timeouts as otherwise websocket connections are closed after ~60-90 seconds
server.headersTimeout = 0;
server.requestTimeout = 0;

Other libs actually implemented some handling for these cases: e.g. vercel/next.js@486b362

It would be nice if this could be somehow addressed as part of this lib.

You want any external libs that can set timeouts to websockets?