Closed ndsun closed 4 years ago
Do you really want MaxConnDuration
or do you want Client.MaxIdleConnDuration
?
MaxConnDuration
will kill the connection even if it just had a request. So it kills connections even if it isstill being used (not during a request). MaxIdleConnDuration
will kill the connection only when it hasn't been used for MaxIdleConnDuration
. This normally makes much more sense as there is no need to kill connections that are still being used.
If you really need MaxConnDuration
in Client
we can easily add it.
Thanks for your reply. I know the differences between MaxConnDuration and MaxIdleConnDuration. And I really need MaxConnDuration.I want't to use it because I don't want a connection always being used, If you can add it, that's very good!
Thank you very much!
I'm curious about how MaxConnDuration works. Does it terminate connections while they are being used by a request?
For example, let's say I created a connection with a timeout of 10 seconds and MaxConnDuration is set to 12 seconds. If a downstream service responds in 9 seconds and another request comes in to reuse the same connection with a timeout of 10 seconds, the connection will be terminated in (12-9)=3 seconds. This can result in a timeout error.
After MaxConnDuration
it will send a Connection: close
header and it will close the connection instead of putting it back into the connection pool. It won't affect the timeout of the request it self. So in your example the 2nd request would still get a 10 second timeout.
when I user fasthttp.Client,why I can not set the MaxConnDuration value.I check the source code, fasthttpClient also user HostClient to send http request, but why HostClient can set MaxConnDuration , Client can't do this?