diff --git a/http2/server.go b/http2/server.go index 3c6b90cc..f79dbcbd 100644 --- a/http2/server.go +++ b/http2/server.go @@ -722,9 +722,13 @@ func (sc *serverConn) serve() { sc.idleTimerCh = sc.idleTimer.C } - var gracefulShutdownCh <-chan struct{} + var gracefulShutdownCh chan struct{} if sc.hs != nil { - gracefulShutdownCh = h1ServerShutdownChan(sc.hs) + ch := h1ServerShutdownChan(sc.hs) + if ch != nil { + gracefulShutdownCh = make(chan struct{}) + go sc.awaitGracefulShutdown(ch, gracefulShutdownCh) + } } go sc.readFrames() // closed by defer sc.conn.Close above @@ -773,6 +777,14 @@ func (sc *serverConn) serve() { } } +func (sc *serverConn) awaitGracefulShutdown(sharedCh <-chan struct{}, privateCh chan struct{}) { + select { + case <-sc.doneServing: + case <-sharedCh: + close(privateCh) + } +} + // readPreface reads the ClientPreface greeting from the peer // or returns an error on timeout or an invalid greeting. func (sc *serverConn) readPreface() error {