Skip to content

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

ts
new HeartbeatMonitor(options): HeartbeatMonitor;

Defined in: packages/client/src/connection/heartbeat.ts:46

Parameters

ParameterType
optionsHeartbeatMonitorOptions

Returns

HeartbeatMonitor

Methods

getStatus()

ts
getStatus(): HeartbeatStatus;

Defined in: packages/client/src/connection/heartbeat.ts:117

Returns the latest heartbeat status snapshot.

Returns

HeartbeatStatus

A shallow copy of the current HeartbeatStatus, including timing and responsiveness information.


markPong()

ts
markPong(): void;

Defined in: packages/client/src/connection/heartbeat.ts:98

Marks a successful heartbeat response.

Returns

void


start()

ts
start(): void;

Defined in: packages/client/src/connection/heartbeat.ts:60

Starts heartbeat interval checks.

Returns

void


stop()

ts
stop(): void;

Defined in: packages/client/src/connection/heartbeat.ts:88

Stops heartbeat interval checks.

Returns

void

Released under the MIT License.