http-party / node-http-proxy

A full-featured http proxy for node.js
https://github.com/http-party/node-http-proxy
Other
13.94k stars 1.98k forks source link

Node 18 will close proxied websocket connections after ~60 seconds #1664

Open reey opened 7 months ago

reey commented 7 months ago

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

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. https://github.com/vercel/next.js/commit/486b36237a213ebf4c19a3bd8f296fad5b400a64

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

ravin00 commented 3 weeks ago

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