-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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/httputil: ReverseProxy gives "context canceled" message when client disappears #20071
Comments
Hi! I think, but I'm not sure, that it would be very easy to add a log specifying that the client has gone away: case <-notifyChan:
p.logf("connection closed by client") // or "client went away" or something like that
cancel() But I still believe it's not necessary. What do you think? |
@matipan that's definitely not clear why context is canceled. I have chain of 3 proxy servers, and middle server was returning "context canceled". It's not really obvious message. |
Is there any way to silence the message? I'm seeing the pretty frequently and starting to realize that it's probably not harmful -- albeit pretty annoying to see in the logs daily. |
I believe https://golang.org/src/net/http/httputil/reverseproxy.go#L234 will report that error since the latest Go minor's versions, one can influence the error logger, trying to match on these context errors. |
Hi @HaraldNordgren did you find a way to silence this error? I am trying to silence it, as my logs are all polluted with this error. Update: i think i found it. Can do something like this:
|
@sergodeeva - we do something like the following, which logs for errors that are not cancels and always returns // noContextCancelationErrors suppresses logging of "context canceled" errors while still
// logging other types of errors.
func noContextCancelationErrors(rw http.ResponseWriter, req *http.Request, err error) {
if err != context.Canceled {
log.Printf("http: proxy error: %v", err)
}
rw.WriteHeader(http.StatusBadGateway)
}
proxy := &httputil.ReverseProxy{
// ...
ErrorHandler: noContextCancelationErrors,
} |
One simple non-breaking way to indicate the reason would be to use |
+1 For @Haegi solution. There needs to be an indicator as to from which side of the proxy the context was cancelled. For my usecase, I don't care if the user disconnected, but I do care if the server on the other side has somehow failed. As of now, only two choices are present:
|
When clients prematurely abandon a proxied HTTP request, there is no identified cause other than "context canceled".
What version of Go are you using (
go version
)?go version go1.8.1 darwin/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
What did you expect to see?
Not entirely sure the right amount of transparency, but it would have been helpful to have something indicating that the client has closed the connection or otherwise gone away.
What did you see instead?
I believe the context is canceled by the following code from
ReverseProxy.ServeHTTP
:The text was updated successfully, but these errors were encountered: