AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Golang http client timeout2/28/2023 ![]() (This might be a bigger problem later, when we try to handle “context canceled” with more nuance.) ![]() This is okay, but I’d prefer more control over it. The timeout interrupts the read connection, then the failed read attempt cancels the request context, then the http.TimeoutHandler (discussed below) receives the signal of that cancellation and sends the 503 response. ![]() However, if a body read follows the timeout, the resulting error will trigger a context cancellation.Ī ReadTimeout during body read results in a log with status of 503. Http.Server timeouts do not themselves cancel the request context. The handler stack (including logging middleware) is not set up until the headers are read. This is even more unfortunate but also not unexpected. This is unfortunate but expected.Ī timeout during header read means that there’s no server log written for the request. These shouldn’t be used for anything but toy servers.Ī timeout during header or body read means that there’s no response to the client. Our TLS terminates at the load balancer, so mention of different TLS behaviour you might see doesn’t apply. (Perhaps it intends the per-request timeout to be done via mw/context rather than via conn deadlines.) “The connection’s read deadline is reset after reading the headers and the Handler can decide what is considered too slow for the body.” “Because ReadTimeout does not let Handlers make per-request decisions on each request body’s acceptable deadline or upload rate, most users will prefer to use ReadHeaderTimeout.” But since http.Request doesn’t provide access to the underlying net.Conn, I don’t see a way to set a connection deadline from the handler level. The documentation makes a big deal out of ReadHeaderTimeout allowing for per-request timeouts based on the headers. It is reset whenever a new request’s header is read.” This effectively covers the lifetime of the ServeHTTP handler stack.
0 Comments
Read More
Leave a Reply. |