Skip to content

trace.GotConn should not be called if dial fails [bug]  #693

@rittneje

Description

@rittneje

Currently this library unconditionally invokes the httptrace.ClientTrace GotConn callback after dialing.

websocket/client.go

Lines 291 to 299 in b65e629

netConn, err := netDial("tcp", hostPort)
if trace != nil && trace.GotConn != nil {
trace.GotConn(httptrace.GotConnInfo{
Conn: netConn,
})
}
if err != nil {
return nil, nil, err
}

However, the documentation from httptrace specifically states that it will only be called after a successful dial. https://pkg.go.dev/net/http/httptrace#ClientTrace

	// GotConn is called after a successful connection is
	// obtained. There is no hook for failure to obtain a
	// connection; instead, use the error from
	// Transport.RoundTrip.
	GotConn func(GotConnInfo)

Consequently, this library should do the error check first.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions