You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I use timeout settings shown above, long running request response (sleeping on purpose - e.g. 7 sec) is always curl: (52) Empty reply from server rather than 503 Service Unavailable and the connection state goes from active to closed. Then the wr.Write() causes ErrHandlerTimeout which is expected as per doc.
What I was expecting is that, response with a 503 Service Unavailable because the server and TimeoutHandler timeouts are same. To achieve this outcome, I'll have to reduce TimeoutHandler duration so it timeouts just before server does - e.g. 4sec. However, timeouts are not inline anymore and cause misunderstanding. Or just remove WriteTimeout which doesn't feel appealing.
Another thing is that, TimeoutHandler is not finely configurable. For example, it doesn't accept Content-Type; body cannot be empty ..... Never mind the actual issue mentioned above, this, on its own is enough for me to ditch TimeoutHandler anyway.
Finally, TimeoutHandler doesn't serve the purpose for me so is there any way of returning 503 Service Unavailable or even better 408 Request Timeout if the server timeouts are met as they are more Request focused?
Thanks
The text was updated successfully, but these errors were encountered:
The Server timeouts are documented to close the connection upon firing. They couldn't do otherwise because if the ReadTimeout fires, the client is still sending the request, while if the WriteTimeout fires the handler might have already started sending the response.
If you make WriteTimeout and TimeoutHandler race, which one wins will be undefined, but I would indeed expect the connection to get closed by the WriteTimeout before TimeoutHandler has a chance to send a response.
If you need to change the behavior of TimeoutHandler, you cam reimplement it in your own code, it does not use any internals as far as I know.
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
http.server
http.server.TimeoutHandler
When I use timeout settings shown above, long running request response (sleeping on purpose - e.g. 7 sec) is always
curl: (52) Empty reply from server
rather than503 Service Unavailable
and the connection state goes fromactive
toclosed
. Then thewr.Write()
causesErrHandlerTimeout
which is expected as per doc.What I was expecting is that, response with a
503 Service Unavailable
because the server andTimeoutHandler
timeouts are same. To achieve this outcome, I'll have to reduceTimeoutHandler
duration so it timeouts just before server does - e.g. 4sec. However, timeouts are not inline anymore and cause misunderstanding. Or just removeWriteTimeout
which doesn't feel appealing.Another thing is that,
TimeoutHandler
is not finely configurable. For example, it doesn't acceptContent-Type
; body cannot be empty ..... Never mind the actual issue mentioned above, this, on its own is enough for me to ditchTimeoutHandler
anyway.Finally,
TimeoutHandler
doesn't serve the purpose for me so is there any way of returning503 Service Unavailable
or even better408 Request Timeout
if the server timeouts are met as they are more Request focused?Thanks
The text was updated successfully, but these errors were encountered: