-
Notifications
You must be signed in to change notification settings - Fork 284
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
Keep alive #450
Keep alive #450
Conversation
keepAliveLimit+=timeout is already a conservative value, as the client set keepAliveLimit to a moment in time before the request was transmitted. So without subtracting 2s, the client's notion of connection timeout will be before the server's notion of it.
Thank you for the investigation and the fix! About the timeout value, though, I'm not sure. The actual client timeout will be about BTW, regarding #448 and not really important here, the TIME_WAIT doesn't really indicate that the server still waits on the connection, but rather that the OS/TCP stack still waits after the connection was actively terminated, it will still occur, regardless of the keep-alive timeout used (but of course just for one or a few connections instead of thousands). |
We have a competing motivation for not making the "PDV compensation" too high. Some servers use a small timeout. For example, Apache 2.2 defaults to 5 seconds http://httpd.apache.org/docs/2.2/mod/core.html#keepalivetimeout Cutting away 2/5 of the seconds available for the uncommon case of 2 seconds of PDV seems like a lot. I guess my thoughts are make this 1 second to allow for some PDV, but still interact well with servers that have a low timeout value. In the end I don't have a strong opinion on this, so I'm going to revert the change so that you can accept the pull request to fix the original bug. |
This reverts commit e9eef52.
As for using an unlimited timeout: Theoretically, yes if the server doesn't respond with a timeout then perhaps it's infinite. In practice, I wonder if some servers have a finite timeout but don't report it to the client. I think the client assuming a maximum timeout of a few minutes is reasonable, and wouldn't really hurt client performance. My experience here is quite limited though, so I don't have a strong opinion on this either. Let me know what you'd like and I'll update the pull request so you can merge it. |
You are right, it will usually not be noticable - but at least it will be a consistent delay, so it would happen even on a completely variation free connection. BTW I was more thinking about fragmented packets due to the MTU or similar when writing this. I think the best would be a 2 step solution:
The only issue with 2 is in cases where a request body was written, the user supplied request callback would have to be invoked twice if the error occurs late (maybe when the response header is being read). This might cause some unexpected things if the callback has side effects. |
Assume keep alive if no "Connection: close" header is present.
Fix for #448
The logic is:
Also I changed
if (m_client.m_timeout > 0 && max > 1)
because keepAliveLimit+=timeout is already a conservative value, as the client set keepAliveLimit to a moment in time before the request was transmitted. So without subtracting 2s, the client's notion of connection timeout will be before the server's notion of it.