Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic in http3.RoundTripper.Close #4457

Closed
ainar-g opened this issue Apr 23, 2024 · 1 comment · Fixed by #4458
Closed

Panic in http3.RoundTripper.Close #4457

ainar-g opened this issue Apr 23, 2024 · 1 comment · Fixed by #4458
Labels
Milestone

Comments

@ainar-g
Copy link

ainar-g commented Apr 23, 2024

Discovered while testing #4456.

Panic occurs in RoundTripper.Close here:

if err := client.conn.CloseWithError(0, ""); err != nil 

My main hypothesis is that this occurs when there is a dialing error. See RoundTripper.getClient:

cl, ok := r.clients[hostname]
if !ok {
	if onlyCached {
		return nil, false, ErrNoCachedConn
	}
	cl = &roundTripperWithCount{
		dialing: make(chan struct{}),
	}
	go func() {
		defer close(cl.dialing)
		conn, rt, err := r.dial(ctx, hostname)
		if err != nil {
			cl.dialErr = err
			return
		}
		cl.conn = conn
		cl.rt = rt
	}()
	r.clients[hostname] = cl
}

Note how cl.conn is only set in the anonymous goroutine if r.dial is successful.

Which means that r.clients can contain clients with conn == nil, but methods Close, CloseIdleConnections, and getClient all lack nil checks and assume that a non-nil *roundTripperWithCount always has a non-nil conn.

@marten-seemann
Copy link
Member

Thanks for reporting. Very valuable to get this resolved before shipping v0.43 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants