Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: Server doesn't use ReadHeaderTimeout for TLS handshake deadline #48120

Closed
bradfitz opened this issue Sep 1, 2021 · 5 comments
Closed

net/http: Server doesn't use ReadHeaderTimeout for TLS handshake deadline #48120

bradfitz opened this issue Sep 1, 2021 · 5 comments

Comments

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Sep 1, 2021

The net/http.Server does:

// Serve a new connection.
func (c *conn) serve(ctx context.Context) {
...
        if tlsConn, ok := c.rwc.(*tls.Conn); ok {
                if d := c.server.ReadTimeout; d > 0 {
                        c.rwc.SetReadDeadline(time.Now().Add(d))
                }
                if d := c.server.WriteTimeout; d > 0 {
                        c.rwc.SetWriteDeadline(time.Now().Add(d))
                }
                if err := tlsConn.HandshakeContext(ctx); err != nil {

But if only Server.ReadHeaderTimeout is set (and not ReadTimeout), it seems like ReadHeaderTimeout should be used for the TLS handshake deadline instead of infinite.

/cc @neild

@komuw
Copy link
Contributor

@komuw komuw commented Sep 1, 2021

related? #35626

@cherrymui cherrymui added this to the Backlog milestone Sep 2, 2021
@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Sep 2, 2021

Yeah, it seems similar to #35626. @bradfitz @neild feel free to close if you think this is a dup. Thanks.

@bradfitz
Copy link
Contributor Author

@bradfitz bradfitz commented Sep 8, 2021

Not a dup, but similar. Different bugs involving the same tunables.

@nulltrope
Copy link
Contributor

@nulltrope nulltrope commented Oct 13, 2021

Just would like to add that this has affected us, as we don't know the nature of the request upfront we can't safely enforce an overall ReadTimeout and instead rely on the ReadHeaderTimeout- but as a consequence have no easy way to set a timeout on the TLS handshake.

To get around this we've used the ConnState func of http.Server to set a connection deadline when state = new, then unset it when state = active, but this seems rather brittle and I feel like would be better served by the higher-level http.Server timeouts.

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 14, 2021

Change https://golang.org/cl/355870 mentions this issue: net/http: also use Server.ReadHeaderTimeout for TLS handshake deadline

@gopherbot gopherbot closed this in b59467e Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants