-
Notifications
You must be signed in to change notification settings - Fork 312
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
Fix dial panic when ctx is nil #365
Conversation
When the ctx is nil, http.NewRequestWithContext returns a "net/http: nil Context" error and a nil request. In this case, the dial function panics because it assumes the req is never nil. This checks the returning error and returns it, so that callers get an error instead of a panic in that scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @guseggert
Co-authored-by: Anmol Sethi <hi@nhooyr.io>
@nhooyr : is this going to get merged? |
LGTM 👍 |
I'm not sure about this anymore. ctx should never be nil. You should just use @BigLep @elimisteve why are you guys running into this? |
Yea there doesn't seem to be a consistent convention on this even in the go stdlib. net.DialContext for example panics on a nil context. https://cs.opensource.google/go/go/+/refs/tags/go1.21.3:src/net/dial.go;l=456 Seems right to me to panic. I'm happy to incorporate the missing err check on |
Thanks @guseggert |
When the ctx is nil, http.NewRequestWithContext returns a "net/http: nil Context" error and a nil request. In this case, the dial function panics because it assumes the req is never nil. This checks the returning error and returns it, so that callers get an error instead of a panic in that scenario.