Here is my observation I have multiple fqdn configured and will try to reach it one by one but only one will respond http2 response and others will fail. I have configured clientTimeout 2s in http.Client and will try first fqdn which will not be resolved in my app to ip and port so request tried with fqdn and port but http2 request takes 4s second to timeout instead of 2s.. I am unable to understand the logic behind it why clientTimeout is discarded. Please share the details or any reference
Can you please share some code that shows what you have tried?
There are many timeouts involved in an HTTP-Request. For example DNS-query happens first to resolve the host name, this can already take a while to complete. After that first a TLS-Handshake needs to be established (including cipher-negotiation, certificate validation, optional revocation check), following this there could be HTTP-redirects or protocol switches (like establishing a websocket) and then finally the actual http-request starts with writing headers, writing body and reading the reply.
There are various timeouts for all stages of this complex process and it’s not easy to combine the right timeouts for your use-case.
If you just want a “end-to-end” timeout for your whole function call, you should probably use a context.WithTimeout()
and pass that to your calls, this will stop after your timeout, no matter in which step the process currently is.