http2: ReadTimeout timer not resetting?

Keep-Alive connections get closed ReadTimeout seconds after connecting, even if they’re actively being used to make HTTP requests:

image

I’m using a ReadTimeout of 5 seconds. As you can see, 5 and 10 seconds after the initial request, the browser has to connect again.

I believe this issue is basically the same as this one: https://github.com/golang/go/issues/16450

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 3
  • Comments: 16 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Also, when I remove http2.ConfigureServerAndConfig(server, tlsConfig) so it uses HTTP/1.1, it doesn’t happen.

Yes, I’m sure.

Chrome: image

Firefox: image

server := &fasthttp.Server{
	ReadTimeout: 5 * time.Second,
	Handler: ServeHTTP,
}

tlsConfig := &tls.Config{...}

http2.ConfigureServerAndConfig(server, tlsConfig)

listener, err := net.Listen("tcp4", "0.0.0.0:443")

if err != nil {
	panic(err)
}

tlsListener := tls.NewListener(listener, tlsConfig)
err = server.Serve(tlsListener)

if err != nil {
	panic(err)
}

The timeout is not working:

image

Server:

server := &fasthttp.Server{
	ReadTimeout: 5 * time.Second,
	Handler:     ServeHTTP,
}

Also:

Servers are encouraged to maintain open connections for as long as possible but are permitted to terminate idle connections if necessary. When either endpoint chooses to close the transport-layer TCP connection, the terminating endpoint SHOULD first send a GOAWAY (Section 6.8) frame so that both endpoints can reliably determine whether previously sent frames have been processed and gracefully complete or terminate any necessary remaining tasks.

From: https://httpwg.org/specs/rfc7540.html#n-connection-management

Maybe you’re misunderstanding the problem.

ReadTimeout documentation:

ReadTimeout is the amount of time allowed to read
the full request including body. The connection's read
deadline is reset when the connection opens, or for
keep-alive connections after the first byte has been read.

Before v0.2.4, the read deadline was only reset when the connection opened, and now read and write timeouts are disabled completely. The expected behavior is the deadline resetting after the first byte of a HTTP request has been read.

Connections are no longer being closed 5 seconds after connecting, but timeouts don’t work at all now.

I’ll let the issue open here, and create a new one in fasthttp