It depends on how far down the connection process it reached before timing out...
What is the timeout setting your http client?
Try this example:
func main() {
trace := &httptrace.ClientTrace{
GetConn: func(hostPort string) {
fmt.Printf("Get Conn: %s\n", hostPort)
},
GotConn: func(connInfo httptrace.GotConnInfo) {
fmt.Printf("Got Conn: %s\n", connInfo.Conn.LocalAddr().String())
},
ConnectStart: func(network, addr string) {
fmt.Printf("Conn start: %s %s\n", network, addr)
},
ConnectDone: func(network, addr string, err error) {
fmt.Printf("Conn done: %s %s\n", network, addr)
},
}
req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace))
client := http.Client{
Timeout: time.Millisecond * 250,
}
if _, err := client.Do(req); err != nil {
log.Fatal(err)
}
}
-----------------------
Output:
--------------------
If you play with the timeout value and set the timeout on the client to be too small, GotConn is not hit because the timeout triggers before acquiring a connection for example due to a TLS handshake delay etc.
>>> I'm not seeing anything in the httptrace library for for a "FailedConnInfo" equivalent to "GotConnInfo." Am I overlooking something?
the GotConn documentation says that for errors look for the error returned by the roundtrip call