-
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: WriteTimeout times out writes before they're written #24461
Comments
This confusing behaviour is the underlying cause of some bug in Mattermost: |
Since this is working as intended and documented as such, and changing the behavior will likely break code (which we can’t do due to the Go 1 compatibility promise), this looks like something to consider for Go2. I’ll let @bradfitz weigh in on it. |
As of Go 1, perhaps, WriteTimeout needs a clearer description. Maybe it's just me, but not only I had to read it several times, but I also had to check the source code to ensure that I understood it correctly. For reference, right now it's like this: // WriteTimeout is the maximum duration before timing out
// writes of the response. It is reset whenever a new
// request's header is read. Like ReadTimeout, it does not
// let Handlers make decisions on a per-request basis.
WriteTimeout time.Duration |
I think this code is working as documented, though no doubt the documentation could be improved. If you set a short timeout, that timeout applies. I can't tell precisely what different behavior you are after; perhaps using a |
CC @bradfitz |
Judging from Moreover, even if So, in my opinion, there're three related, but separate issues:
As of documentation, Mattermost configuration page has this clear and accurate description what |
We can update docs if you have a suggestion for what would clarify it, but like others said, we can't change behavior here. The real feature request bug that people are interested in is #16100, to manipulating timeouts within a Handler. |
(related to #21389)
What version of Go are you using (
go version
)?I checked
go version go1.10 linux/amd64
andgo version go1.9.4 linux/amd64
, which behave the same.Does this issue reproduce with the latest release?
Yeah.
What operating system and processor architecture are you using (
go env
)?What did you do?
I set
WriteTimeout
to some value, which was smaller than the time handler took to handle the request.https://gist.github.com/WGH-/90bbfe656e63f6fa457db84f91384c41
What did you expect to see?
Well, the documentation clearly states "It is reset whenever a new request's header is read.", after all. So strictly speaking, everything is working as intended.
However, I expected that
WriteTimeout
would only timeout write calls that're taking too long, or at least that it would start ticking at the first write. It would make much more sense this way.What did you see instead?
As soon as server tries to write anything, even it hasn't written anything before, assuming timeout is passed, it will close the connection.
The text was updated successfully, but these errors were encountered: