diff --git a/src/net/http/serve_test.go b/src/net/http/serve_test.go index fd2dd6cea5..6b450d41e3 100644 --- a/src/net/http/serve_test.go +++ b/src/net/http/serve_test.go @@ -4943,9 +4943,6 @@ func TestServerSetKeepAlivesEnabledClosesConns(t *testing.T) { }) { t.Fatalf("idle count before SetKeepAlivesEnabled called = %v; want 1", idle0) } - if !waitCondition(2*time.Second, 10*time.Millisecond, ts.Config.ExportAllConnsIdle) { - t.Fatalf("test server has active conns") - } ts.Config.SetKeepAlivesEnabled(false) diff --git a/src/net/http/server.go b/src/net/http/server.go index 8a79a6c6a4..be76c6a9c0 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -1827,6 +1827,14 @@ func (c *conn) serve(ctx context.Context) { c.setState(c.rwc, StateIdle) c.curReq.Store((*response)(nil)) + if !w.conn.server.doKeepAlives() { + // We're in shutdown mode. We might've replied + // to the user without "Connection: close" and + // they might think they can send another + // request, but such is life with HTTP/1.1. + return + } + if d := c.server.idleTimeout(); d != 0 { c.rwc.SetReadDeadline(time.Now().Add(d)) if _, err := c.bufr.Peek(4); err != nil {