diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2016-11-14 22:11:05 +0000 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-11-14 22:39:50 +0000 |
| commit | bb00a8d97faa70bf7a1cbdd4a43e95347a9c8709 (patch) | |
| tree | 1018b4fbe3a9ecfc5415c1e8013c3306d5873dbe /src/net/http/h2_bundle.go | |
| parent | b83350a2e05d63eaae8da9ff4f957ab44e4cb9d9 (diff) | |
| download | go-bb00a8d97faa70bf7a1cbdd4a43e95347a9c8709.tar.xz | |
net/http: update bundled http2, add TestServerKeepAlivesEnabled h1/h2 tests
Updates x/net/http2 to x/net git rev 6dfeb344 for:
http2: make Server respect http1 Server's SetKeepAlivesEnabled
https://golang.org/cl/33153
And adds a test in std.
Fixes #17717
Change-Id: I3ba000abb6f3f682261e105d8a4bb93bde6609fe
Reviewed-on: https://go-review.googlesource.com/33231
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tom Bergan <tombergan@google.com>
Diffstat (limited to 'src/net/http/h2_bundle.go')
| -rw-r--r-- | src/net/http/h2_bundle.go | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/src/net/http/h2_bundle.go b/src/net/http/h2_bundle.go index 20178dadf1..085a6fab54 100644 --- a/src/net/http/h2_bundle.go +++ b/src/net/http/h2_bundle.go @@ -3549,7 +3549,7 @@ func (sc *http2serverConn) serve() { return case <-gracefulShutdownCh: gracefulShutdownCh = nil - sc.goAwayIn(http2ErrCodeNo, 0) + sc.startGracefulShutdown() case <-sc.shutdownTimerCh: sc.vlogf("GOAWAY close timer fired; closing conn from %v", sc.conn.RemoteAddr()) return @@ -3834,6 +3834,13 @@ func (sc *http2serverConn) scheduleFrameWrite() { sc.inFrameScheduleLoop = false } +// startGracefulShutdown sends a GOAWAY with ErrCodeNo to tell the +// client we're gracefully shutting down. The connection isn't closed +// until all current streams are done. +func (sc *http2serverConn) startGracefulShutdown() { + sc.goAwayIn(http2ErrCodeNo, 0) +} + func (sc *http2serverConn) goAway(code http2ErrCode) { sc.serveG.check() var forceCloseIn time.Duration @@ -4028,12 +4035,15 @@ func (sc *http2serverConn) closeStream(st *http2stream, err error) { } else { sc.curClientStreams-- } - if sc.curClientStreams+sc.curPushedStreams == 0 { - sc.setConnState(StateIdle) - } delete(sc.streams, st.id) - if len(sc.streams) == 0 && sc.srv.IdleTimeout != 0 { - sc.idleTimer.Reset(sc.srv.IdleTimeout) + if len(sc.streams) == 0 { + sc.setConnState(StateIdle) + if sc.srv.IdleTimeout != 0 { + sc.idleTimer.Reset(sc.srv.IdleTimeout) + } + if http2h1ServerKeepAlivesDisabled(sc.hs) { + sc.startGracefulShutdown() + } } if p := st.body; p != nil { @@ -4177,7 +4187,7 @@ func (sc *http2serverConn) processGoAway(f *http2GoAwayFrame) error { } else { sc.vlogf("http2: received GOAWAY %+v, starting graceful shutdown", f) } - sc.goAwayIn(http2ErrCodeNo, 0) + sc.startGracefulShutdown() sc.pushEnabled = false return nil @@ -5181,7 +5191,7 @@ func (sc *http2serverConn) startPush(msg http2startPushRequest) { } if sc.maxPushPromiseID+2 >= 1<<31 { - sc.goAwayIn(http2ErrCodeNo, 0) + sc.startGracefulShutdown() return 0, http2ErrPushLimitReached } sc.maxPushPromiseID += 2 @@ -5326,6 +5336,20 @@ func http2h1ServerShutdownChan(hs *Server) <-chan struct{} { // optional test hook for h1ServerShutdownChan. var http2testh1ServerShutdownChan func(hs *Server) <-chan struct{} +// h1ServerKeepAlivesDisabled reports whether hs has its keep-alives +// disabled. See comments on h1ServerShutdownChan above for why +// the code is written this way. +func http2h1ServerKeepAlivesDisabled(hs *Server) bool { + var x interface{} = hs + type I interface { + doKeepAlives() bool + } + if hs, ok := x.(I); ok { + return !hs.doKeepAlives() + } + return false +} + const ( // transportDefaultConnFlow is how many connection-level flow control // tokens we give the server at start-up, past the default 64k. |
