lspeasy / client/src / HeartbeatMonitor
Class: HeartbeatMonitor
Defined in: packages/client/src/connection/heartbeat.ts:42
Runs interval-based heartbeat checks for active transports.
Remarks
Created internally by LSPClient when ClientOptions.heartbeat is configured. The monitor periodically sends a ping (via onPing) and checks whether a pong was received within timeout ms. If not, onUnresponsive is called so the client can close and attempt to reconnect.
Use When
You need to detect silent transport failures — for example, when the server process dies without closing the socket, leaving the client hanging indefinitely on pending requests.
Avoid When
The transport already provides its own keep-alive mechanism (e.g. WebSocket ping frames) — adding a heartbeat on top creates redundant round-trips and may interfere with the transport's own timeout logic.
Never
NEVER set interval shorter than the typical round-trip latency for your transport — doing so causes constant onUnresponsive callbacks on any non-local transport, triggering spurious reconnects.
NEVER rely on heartbeat for authentication or access control. The heartbeat only confirms the transport is alive; it carries no identity information.
Constructors
Constructor
new HeartbeatMonitor(options): HeartbeatMonitor;Defined in: packages/client/src/connection/heartbeat.ts:46
Parameters
| Parameter | Type |
|---|---|
options | HeartbeatMonitorOptions |
Returns
HeartbeatMonitor
Methods
getStatus()
getStatus(): HeartbeatStatus;Defined in: packages/client/src/connection/heartbeat.ts:117
Returns the latest heartbeat status snapshot.
Returns
A shallow copy of the current HeartbeatStatus, including timing and responsiveness information.
markPong()
markPong(): void;Defined in: packages/client/src/connection/heartbeat.ts:98
Marks a successful heartbeat response.
Returns
void
start()
start(): void;Defined in: packages/client/src/connection/heartbeat.ts:60
Starts heartbeat interval checks.
Returns
void
stop()
stop(): void;Defined in: packages/client/src/connection/heartbeat.ts:88
Stops heartbeat interval checks.
Returns
void