-
Notifications
You must be signed in to change notification settings - Fork 28.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
server.keepAliveTimeout
is not applied to sockets that are never used.
#23981
Comments
By "long time" you mean 120 seconds, the |
Yes, 120 seconds, default value of |
@mcollina has a change on the way that I think will address this for you. Its part of some other work, so it'll be a while before it is ready for a PR. I'll link to it when it is. |
I don't think my change will cover this. |
OK, I'll take a look at it. |
@asyncmax Btw, have you considered doing |
If we are looking for a workaround, we will be able to come up with some clever ways. Your suggestion can be certainly one of them (default timeout value of 5 seconds for The following snippet is how I workaround this problem for now. server.on("connection", socket => {
if (server.keepAliveTimeout)
socket.setTimeout(server.keepAliveTimeout);
});
server.on("request", req => {
req.setTimeout(server.timeout || 0);
}); However, I reported this issue because I thought this should be addressed in the Node core. In my opinion, sockets that are in their initial state (never used) are effectively the same as sockets that are in an idle state between requests. I don’t believe we need to introduce another type of timeout. |
@sam-github Are you still looking into this? (Not trying to rush you or anything, but do want to update the assignee and labeling if this is not going moving.) |
Yes, still looking at it. |
This is still a problem. |
I am looking at this and in fact the change is very simple to implement |
I think the current behavior is correct. A connection is flagged as keep alive after the first request is received because the client signals it to the server with the Note that https://nodejs.org/api/http.html#http_server_requesttimeout should also help. |
Currently,
server.keepAliveTimeout
is applied to a socket only after the first response is sent out by the server. If a client connects to the server but does not send any requests, the idle socket is kept open untilserver.timeout
is reached (120 seconds by default).My understanding is that
server.keepAliveTimeout
was added in Node v8.0.0 to reduce the number of unused idle sockets and in turn to reduce the overhead of the server. But unused sockets can still hang around. We can easily observe this behavior in Chrome which opens sockets that are never used but kept alive for a long time.I believe that a socket which has never been used should be treated the same as a
keepAlive
socket awaiting the next request and should be closed afterserver.keepAliveTimeout
elapses.The text was updated successfully, but these errors were encountered: