@@ -28,7 +28,7 @@ import (
28
28
"time"
29
29
30
30
"camlistore.org/pkg/googlestorage"
31
- "camlistore .org/pkg /singleflight"
31
+ "go4 .org/syncutil /singleflight"
32
32
"golang.org/x/net/http2"
33
33
)
34
34
@@ -79,7 +79,7 @@ is used transparently by the Go standard library from Go 1.6 and later.
79
79
</p>
80
80
81
81
<p>Contact info: <i>[email protected] </i>, or <a
82
- href="https://golang.org/issues ">file a bug</a>.</p>
82
+ href="https://golang.org/s/http2bug ">file a bug</a>.</p>
83
83
84
84
<h2>Handlers for testing</h2>
85
85
<ul>
@@ -440,11 +440,43 @@ func serveProd() error {
440
440
return <- errc
441
441
}
442
442
443
+ const idleTimeout = 5 * time .Minute
444
+ const activeTimeout = 10 * time .Minute
445
+
446
+ // TODO: put this into the standard library and actually send
447
+ // PING frames and GOAWAY, etc: golang.org/issue/14204
448
+ func idleTimeoutHook () func (net.Conn , http.ConnState ) {
449
+ var mu sync.Mutex
450
+ m := map [net.Conn ]* time.Timer {}
451
+ return func (c net.Conn , cs http.ConnState ) {
452
+ mu .Lock ()
453
+ defer mu .Unlock ()
454
+ if t , ok := m [c ]; ok {
455
+ delete (m , c )
456
+ t .Stop ()
457
+ }
458
+ var d time.Duration
459
+ switch cs {
460
+ case http .StateNew , http .StateIdle :
461
+ d = idleTimeout
462
+ case http .StateActive :
463
+ d = activeTimeout
464
+ default :
465
+ return
466
+ }
467
+ m [c ] = time .AfterFunc (d , func () {
468
+ log .Printf ("closing idle conn %v after %v" , c .RemoteAddr (), d )
469
+ go c .Close ()
470
+ })
471
+ }
472
+ }
473
+
443
474
func main () {
444
475
var srv http.Server
445
476
flag .BoolVar (& http2 .VerboseLogs , "verbose" , false , "Verbose HTTP/2 debugging." )
446
477
flag .Parse ()
447
478
srv .Addr = * httpsAddr
479
+ srv .ConnState = idleTimeoutHook ()
448
480
449
481
registerHandlers ()
450
482
0 commit comments