client.Do() a crashes When creating a new http.Client{} with timeout
|
func (c *Client) Do(req *Request) (*Response, error) { |
|
if c.Transport != nil { |
|
return c.Transport.RoundTrip(req) |
|
} |
|
|
|
return c.do(req) |
|
} |
|
if !deadline.IsZero() && didTimeout() { |
Seems like the when creating a client the transport is nil, which causes the .Do() to use tls.Dial, which returns an error, but the func didTimeout is never initialized like on net/http in Go https://github.com/golang/go/blob/d00c67f297ef6f2cb2cd0e9aae59fa3936bb7eca/src/net/http/client.go#L264
Error
❯ ./app
panic: runtime error at 0x000000000024bd02: nil pointer dereference
fish: Job 1, './app' terminated by signal SIGABRT (Abort)
POC
package main
import (
"log"
"net/http"
"time"
)
func main() {
c := http.Client{
Timeout: 2 * time.Second,
}
rs, _ := http.NewRequest("GET", "https://google.com", nil)
r, e := c.Do(rs)
if e != nil {
log.Println(e)
} else {
log.Println(r.Status)
}
}
client.Do()a crashes When creating a newhttp.Client{}with timeoutnet/http/client.go
Lines 433 to 439 in 1026408
net/http/client.go
Line 461 in 1026408
Seems like the when creating a client the transport is
nil, which causes the.Do()to usetls.Dial, which returns an error, but the funcdidTimeoutis never initialized like onnet/httpin Go https://github.com/golang/go/blob/d00c67f297ef6f2cb2cd0e9aae59fa3936bb7eca/src/net/http/client.go#L264Error
❯ ./app panic: runtime error at 0x000000000024bd02: nil pointer dereference fish: Job 1, './app' terminated by signal SIGABRT (Abort)POC