uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
7.86k stars 569 forks source link

HTTP connection Timeout then half closed socket #770

Closed uasan closed 2 years ago

uasan commented 2 years ago

We are using a proxy that has HTTP connection pool to uWebSockets.js backend. If a connection from the pool is idle for more than 20 minutes, requests sent to this connection are not processed, it looks like the incoming connection was closed on the server side and it is in a half-closed state, the proxy did not receive a close signal and is trying to use this connection, this is still an assumption based on behavior this errors. Has anyone had a similar experience or have other thoughts?

uasan commented 2 years ago

close any http connection that is idle for more than 10 seconds

Is this value 10 seconds configurable or hard coded? If this value cannot be changed, will you close connections if I use tcp_keepalive_time with a value less than 10 seconds?

uasan commented 2 years ago

But why do you need them open?

For some unknown reason, the proxy considers connections that the server timeout to be open connections. This is a stupid logic of the proxy connection pool, it keeps the pool even when there is no traffic, I can’t fix the proxy logic, so I’m looking for options on how to fix it on server side.

uasan commented 2 years ago

itsio envoy - it works slower than our backend, but the business client required it, it's all on AWS https://istio.io/latest/

uasan commented 2 years ago

This may have been discussed but I couldn't find it.

If the handler is assigned in the next microtask after receiving the request, will the onData event occur or is there a risk that in the previous microtask the server read the entire request body and the event assigned in the next microtask will never wait for the call and I will never receive the body of this request? Example, code:

rout.post('/', async (res, req) => {
 let isAborted = false;
 res.onAborted(() => { isAborted = true });

 await asyncMethod();

 if (isAborted === false) {
     res.onData(() => {
        //... Is there a risk that I started listening too late and the request body is no longer readable?
     })
  }
})
uasan commented 2 years ago

I thought so, it seems that this is the reason for the 504 error from the proxy, I get into eternal waiting and the proxy is not to blame.

uasan commented 2 years ago

Thanks, I'm closing the ticket.