-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
net/http: HTTP CONNECT failures should return a more helpful error #38143
Comments
Thank you for filing this bug @elagergren-spideroak and great to catch you here! I can sympathize with this problem, and this code was written almost a decade ago (~9 years ago) Thank you for the suggestion to add ConnectError, but given that I've encountered this problem and I think that there might other places that could use StatusCode and message, perhaps let's make it type CodedError struct {
Code int
Message string
Method string
}
type (ce *CodedError) Error() string { return ce.Message } and in usage you can do: resp, err := c.Get(...)
if err != nil {
ce, ok := err.(*http.CodedError)
if !ok {
return err
}
// Otherwise check and deal with backoff + retries.
...
} That type can also be generalized for use in other packages like the net, in which for example we can provide more details on why a Dial failed, but also specify where in the dialling stack it failed, by specifying Method. One thing we'll need to be aware of, if we add this error is: |
For what it's worth, I'm not too concerned about the actual error— However, like you mentioned, ensuring backwards compatibility is important, thus why in my example the Comparisons with the current error always evaluate to false, so I can't imagine anybody relying on the behavior. |
@gopherbot remove WaitingForInfo |
Change https://golang.org/cl/289929 mentions this issue: |
@odeke-em @andybons @ericlagergren Hello, I raised a PR that would address this (and its duplicates) a few months ago but haven't received any feedback on my PR. Could you please help out? |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yep
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/CsZfrDwLeFb
What did you expect to see?
An error I could inspect.
What did you see instead?
A
*url.Error
with itsErr
set toerrors.New(...)
.In certain environments we use HTTP CONNECT, and on occasion some of the destination servers are temporarily unreachable. When this happens with other proxies, we can inspect the HTTP response (status codes and/or headers) or the error (does Temporary report true?) to determine whether we should backoff and retry the request.
However, net/http inspects the response from the initial CONNECT request and if it's anything other than 200, it returns an generic error constructed from the status code text:
go/src/net/http/transport.go
Line 1622 in 564c76a
This means we're limited to something like
An example of a useful error would be something like
The text was updated successfully, but these errors were encountered: