18

How long the connection will be kept alive in Http/2? I understand the Http/2 uses one connection per domain and does multiplexing. But I didn't get any information on how long the connection will be kept alive.

Muhammad Asadullah
  • 3,735
  • 1
  • 22
  • 38
Navin GV
  • 700
  • 3
  • 10
  • 24
  • 1
    link: https://stackoverflow.com/questions/70718831/how-do-i-convey-keep-alive-metadata-when-the-http-2-protocol-is-used – NicoNing Feb 06 '23 at 10:18
  • 1
    https://stackoverflow.com/questions/58819199/how-to-keep-long-connection-in-http2 – NicoNing Feb 06 '23 at 10:19

1 Answers1

26

As with HTTP/1.1, the time a connection is kept alive in HTTP/2 depends on the implementation of the client and server. The HTTP/2 specification says

HTTP/2 connections are persistent. For best performance, it is expected that clients will not close connections until it is determined that no further communication with a server is necessary (for example, when a user navigates away from a particular web page) or until the server closes the connection.

[...]

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.

So, both endpoints can gracefully close a connection by sending a GOAWAY frame. Nginx and Apache let you configure a timeout after which an idle HTTP/2 connection is closed. The default value for nginx is 3 minutes, for Apache it is 5 seconds.

Community
  • 1
  • 1
sauerburger
  • 4,569
  • 4
  • 31
  • 42