-
Notifications
You must be signed in to change notification settings - Fork 83
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
Manage HTTP/2 connections and keep them alive with PING frames #673
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ead of a session manager instance
smaye81
approved these changes
Jun 13, 2023
Merged
This was referenced Jun 20, 2023
Merged
16 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support Basic Keepalive for HTTP/2 for clients that use one of the transports from
@bufbuild/connect-node
.It replaces the option
keepSessionAlive
, which is deprecated with this PR.In it's most simple form, the following example enables regular PINGs every 5 minutes:
With the example above, PING frames are only sent for connections that have open streams (running RPCs). The following options are available to tweak the behavior depending on the requirements.
pingIntervalMs?: number
The interval to send PING frames to keep a connection alive. The interval is reset whenever a stream receives data. If a PING frame is not responded to within
pingTimeoutMs
, the connection and all open streams close.By default, no PING frames are sent. If a value is provided, PING frames are sent only for connections that have open streams, unless
pingIdleConnections
is enabled.Sensible values can be between 10 seconds and 2 hours, depending on your infrastructure.
This option is equivalent to
GRPC_ARG_KEEPALIVE_TIME_MS
in gRPC Core.pingIdleConnection?: boolean
Enable PING frames for connections that are have no open streams. This option is only effective if a value for pingIntervalMs is provided.
Note that it may not be necessary to enable this option. If a request is made on a connection that has not been used for longer than
pingIntervalMs
, a PING frame is sent to verify that the connection is still alive, and a new connection is opened transparently if necessary.Defaults to false.
This option is equivalent to
GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS
in gRPC Core.pingTimeoutMs?: number
Timeout for PING frames. If a PING is not answered within this time, the connection is considered dead.
Defaults to 15 seconds. This option is only used if a value for pingIntervalMs is provided.
This option is equivalent to
GRPC_ARG_KEEPALIVE_TIME_MS
in gRPC Core.idleConnectionTimeoutMs?: number
Automatically close a connection if the time since the last request stream exceeds this value.
Defaults to 15 minutes.
This option is equivalent to
GRPC_ARG_CLIENT_IDLE_TIMEOUT_MS
of gRPC core.Sessions and keep-alive are managed by the class
Http2SessionManager
from@bufbuild/connect-node
. This class can be used to gain control over the session used by the transport by creating it ahead of time, and passing the instance to the transport constructor function. The following example shows how to explicitly close a HTTP/2 connection: