/ go Public
net/http: no way to get server Handler's write error to client (sometimes) #28271
Feedback is required from experts, contributors, and/or the community before a change can be made.
What version of Go are you using (
Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
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.
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:
Perhaps this could be achieved by having
conn.werrif 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
The text was updated successfully, but these errors were encountered: