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

net/http: no way to get server Handler's write error to client (sometimes) #28271

muirrn opened this issue Oct 18, 2018 · 0 comments


None yet
2 participants
Copy link

commented Oct 18, 2018

What version of Go are you using (go version)?


Does this issue reproduce with the latest release?


What operating system and processor architecture are you using (go env)?


What did you do?

I wrote an http response after the client socket was closed.

What did you expect to see?

I expected to be able to get the write error somehow.

What did you see instead?

There does not seem to be any way to get the write error, even after flushing.

More background:

The use case is we had an http handler that took too long to respond. After figuring out what happened, we wanted to make sure our http server logged all errors writing responses so it would be easy to see this happening in the future.

In our particular case, we weren't actually writing a body (we only called WriteHeader). I was hoping I could do something like this in a middleware to log response errors in a generic way:

nextHandler(w, r)
if flusher, ok := w.(http.Flusher); ok {
  if _, err := w.Write(nil); err != nil {
    // log "err" for posterity

Perhaps this could be achieved by having http.response.write return conn.werr if it is set?

It is worth mentioning that the request context is cancelled in this case, so that could be used to detect the client is gone. However, I expected there to be someway to get the actual Write error.

@bradfitz bradfitz changed the title net/http: no way to get error writing response (sometimes) net/http: no way to get server Handler's write error to client (sometimes) Oct 18, 2018

@bradfitz bradfitz added this to the Unplanned milestone Oct 18, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.