Package reactor.netty.http
Class Http2ConnectionLiveness
java.lang.Object
reactor.netty.http.Http2ConnectionLiveness
- All Implemented Interfaces:
HttpConnectionLiveness
Supports connection health checks using HTTP/2 PING frames.
This class implements liveness detection for HTTP/2 connections by sending PING frames when the connection becomes idle (no read/write activity). The peer must respond with a PING ACK within the configured timeout, otherwise the connection is considered unresponsive.
Behavior
- PING frames are only sent when the connection is idle (no active reads/writes)
- Each PING frame must receive an ACK within
pingAckTimeout - If no ACK is received, retry up to
pingAckDropThresholdtimes - If all attempts fail, the connection is closed
- Receiving any HTTP/2 frame (HEADERS, DATA, or PING ACK) cancels the health check
Thread Safety
This class is designed to be used with a single channel. All operations, including scheduled tasks, execute on the channel's event loop thread, eliminating the need for explicit synchronization. A new instance is created per channel.
Configuration Guidelines
- pingAckTimeout: Should account for expected network latency and load. Values that are too short may cause false positives due to temporary delays.
- pingAckDropThreshold: Balance between quick failure detection and tolerance for transient issues. Higher values increase detection time but reduce false positives.
- Since:
- 1.2.12
- Author:
- raccoonback, Violeta Georgieva
-
Field Summary
Fields inherited from interface reactor.netty.http.HttpConnectionLiveness
CLOSE, log -
Constructor Summary
ConstructorsConstructorDescriptionHttp2ConnectionLiveness(Http2FrameCodec http2FrameCodec, int pingAckDropThreshold, long pingAckTimeoutNanos) Constructs a newHttp2ConnectionLivenessinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Cancels the scheduled ping task.voidChecks the liveness of the connection and schedules a ping if necessary.voidReceives a message from the peer and processes it if it is a ping frame.
-
Constructor Details
-
Http2ConnectionLiveness
public Http2ConnectionLiveness(Http2FrameCodec http2FrameCodec, int pingAckDropThreshold, long pingAckTimeoutNanos) Constructs a newHttp2ConnectionLivenessinstance.- Parameters:
http2FrameCodec- the HTTP/2 frame codecpingAckDropThreshold- the maximum number of PING frame transmission attempts before closing the connectionpingAckTimeoutNanos- the timeout in nanoseconds for receiving a PING ACK response
-
-
Method Details
-
cancel
public void cancel()Cancels the scheduled ping task.- Specified by:
cancelin interfaceHttpConnectionLiveness
-
check
Checks the liveness of the connection and schedules a ping if necessary.- Specified by:
checkin interfaceHttpConnectionLiveness- Parameters:
ctx- theChannelHandlerContextof the connection
-
receive
Receives a message from the peer and processes it if it is a ping frame.- Specified by:
receivein interfaceHttpConnectionLiveness- Parameters:
msg- the message received from the peer
-