Context deadline is not returned with timeout error

This issue is in setRequestCancel line 375 in clien.go.
I have set client.Timeout 3s and called client.Do to send http2 request, as per source code client.go in package net/http, context with deadline is called but timeout does not occur and it goes to round trip which have fqdn as host(it is just issue in our code).
After 4s, every time error is returned then cancel is called.
As per my observation context is done after 3s but no action done to exit using rt.CancelRequest from ongoing send req handling
could anyone help to understand why this timeout does not occur for invalid host set in http2 request?

You are going to need to post some example code.

Below are the example code… nfDomain1.namespace1 is not there in kubernetes cluster… client.Do takes 4s for that although i have 2s as client timeout…

url := http://nfDomain1.namespace1/initial
data := “some data”
postReq, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(data))
if err != nil {
return nil
client := &http.Client{
Transport: &http2.Transport{
AllowHTTP: true,
DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) {
return net.DialTimeout(network, addr, (2000)*time.Millisecond)
PingTimeout: 2000 * time.Millisecond,
ReadIdleTimeout: 2000 * time.Millisecond,
Timeout: 2000 * time.Millisecond,
// i have set 2s as client Timeout but error received after 4s everytime
resp, err := client.Do(postReq)
if err != nil {
return nil

Above code is working but with my application there is a delay in client.Do
above code is returning below error

time 2.001242093s 2024-04-08 10:18:27.139158269 +0000 UTC m=+2.001778206 Post “http://udr-subs.:3000/”: dial tcp: lookup udr-subs.: i/o timeout (Client.Timeout exceeded while awaiting headers)

my application returns this error after 4s
Post "http://udr-subs.:3000/": dial tcp: lookup udr-subs. on is dns may be in here issue is there): server misbehaving (Client.Timeout exceeded while awaiting headers)

Any solution is there for this issue