Hello everyone, I came across a behavior while debugging an http server 
graceful shutdown which made wonder:

1. As a mitigation to this issue: https://github.com/golang/go/issues/22682
We've added the following check to `closeIdleConns`:
```
+ // Issue 22682: treat StateNew connections as if
+ // they're idle if we haven't read the first request's
+ // header in over 5 seconds.
+ if st == StateNew && unixSec < time.Now().Unix()-5 {
+ st = StateIdle
+ }
```

I was wondering if it would've made sense to consider `ReadHeaderTimeout` 
here when set, fall-backing to the default of 5 seconds; maybe taking the 
max of them.


2. I was wondering if it would've made sense to allow configuring a 
pre-close idle duration on the server, or a pre-close hook, that would 
allow closing only connections that had been idle for at least some time.

I'm dealing w/ a scenario where this would've been beneficial - 
There appears to be a small race during a version rollout and graceful 
termination of an http1 server,
where actively used connections in a burst period toggle between active / 
idle - and just before an idle conn is closed, it's re-used by a client, 
which then receives EOF and doesn't retry the operation, as the operation 
is non idempotent (say, http POST) -
this subsequently leads to some unfortunate side effects on the client side.

Having the ability to fine tune the closing of idle connections could allow 
narrowing this race window, if say, a user configures the server to only 
close connections that are idle for at least 5 seconds, or until the ctx is 
canceled;

I believe I can implement both above elegantly in `closeIdleConns`, and was 
wondering if this is something you'd consider.


Appreciate your time on the manner,
Danny

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/07c3d2c7-f524-450c-97ae-97841a6d2ae0n%40googlegroups.com.

Reply via email to