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
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@bradfitz
Copy link
Contributor

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 commented Sep 1, 2021

related? #35626

@cherrymui cherrymui added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 2, 2021
@cherrymui cherrymui added this to the Backlog milestone Sep 2, 2021
@cherrymui
Copy link
Member

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 commented Sep 8, 2021

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

@nulltrope
Copy link
Contributor

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

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

@golang golang locked and limited conversation to collaborators Oct 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants