With Go 1.8, IdleTimeout was introduced:
// IdleTimeout is the maximum amount of time to wait for the
// next request when keep-alives are enabled. If IdleTimeout
// is zero, the value of ReadTimeout is used. If both are
// zero, there is no timeout.
I've found that setting IdleTimeout like so:
timeouts {
idle 5m
}
vastly reduces the number of goroutines that stay open over time, presumably because even if the network link is active, there are no actual HTTP requests over the connection, and so the connections are not needed.
In the past, Caddy had default timeouts enabled (#1368) as a security precaution, but it broke a lot of people (just search the issues or forum) so I removed all default timeouts.
However, I suspect that setting IdleTimeout to a non-zero value by default will be beneficial without disrupting people's existing sites. It will reduce the number of goroutines that stay alive unnecessarily and free up file descriptors. Here's a tweet with some more evidence: https://twitter.com/mholt6/status/872257089296416768
I propose a default idle timeout of 5 minutes. Any feedback is welcome here.
Sounds good to me :+1:
@mholt @elcore Hey there!! I'd love to help. Do you guys I can implement the default value for IdleTimeout? If so, would be awesome if u guys could point me in the right direction to get this done. :)
I am in favour of this. +1
@klebervirgilio Sure, go for it! It might be as simple as setting a field in defaultTimeouts here. Make sure to test it yourself and then write a test in the server_test.go file to verify it works. The test should fail without your change!
@klebervirgilio Any update on this? We're almost ready to push out the next version of Caddy.
@mholt Sorry for the delay! will work on this asap!
@klebervirgilio Sounds good! Let me know if I can help, I want to get a release out... tomorrow, I think.
@klebervirgilio Sorry, but I just went ahead and did it today; as it is an important part of today's release. However, there's plenty of work to do, and I hope you will contribute on another issue!
Most helpful comment
@mholt Sorry for the delay! will work on this asap!