Skip to content

Commit 7181118

Browse files
WineChordgopherbot
authored andcommitted
net/http: check server shutting down before processing the request
The root cause of issue #65802 is a small race condition that occurs between two events: 1. During the HTTP server shutdown, a connection in an idle state is identified and closed. 2. The connection, although idle, has just finished reading a complete request before being closed and hasn't yet updated its state to active. In this scenario, despite the connection being closed, the request continues to be processed. This not only wastes server resources but also prevents the client request from being retried. Fixes #65802 Change-Id: Ic22abb4497be04f6c84dff059df00f2c319d8652 GitHub-Last-Rev: 426099a GitHub-Pull-Request: #65805 Reviewed-on: https://go-review.googlesource.com/c/go/+/565277 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> Reviewed-by: Sean Liao <[email protected]> Reviewed-by: Damien Neil <[email protected]> Auto-Submit: Sean Liao <[email protected]>
1 parent bef2bb8 commit 7181118

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/net/http/server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,6 +2006,9 @@ func (c *conn) serve(ctx context.Context) {
20062006
// If we read any bytes off the wire, we're active.
20072007
c.setState(c.rwc, StateActive, runHooks)
20082008
}
2009+
if c.server.shuttingDown() {
2010+
return
2011+
}
20092012
if err != nil {
20102013
const errorHeaders = "\r\nContent-Type: text/plain; charset=utf-8\r\nConnection: close\r\n\r\n"
20112014

0 commit comments

Comments
 (0)