From 9853e6b631f818801f98bf287e014a43303128de Mon Sep 17 00:00:00 2001 From: "Hsing-Yu (David) Chen" Date: Mon, 16 Dec 2024 13:27:18 -0500 Subject: [PATCH] net/http: consolidate read/write deadline calls into SetDeadline The updated code seems to be more concise and retains the original behavior: "SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline." (from https://pkg.go.dev/net#Conn) --- src/net/http/server.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/net/http/server.go b/src/net/http/server.go index 1e8e1437d26832..5a431e1f488843 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -1965,8 +1965,7 @@ func (c *conn) serve(ctx context.Context) { tlsTO := c.server.tlsHandshakeTimeout() if tlsTO > 0 { dl := time.Now().Add(tlsTO) - c.rwc.SetReadDeadline(dl) - c.rwc.SetWriteDeadline(dl) + c.rwc.SetDeadline(dl) } if err := tlsConn.HandshakeContext(ctx); err != nil { // If the handshake failed due to the client not speaking @@ -1985,8 +1984,7 @@ func (c *conn) serve(ctx context.Context) { } // Restore Conn-level deadlines. if tlsTO > 0 { - c.rwc.SetReadDeadline(time.Time{}) - c.rwc.SetWriteDeadline(time.Time{}) + c.rwc.SetDeadline(time.Time{}) } c.tlsState = new(tls.ConnectionState) *c.tlsState = tlsConn.ConnectionState()