Skip to main content
Lasso uses WebSocket ping/pong frames to detect disconnected clients. Keep your client responsive and reconnect when the connection closes.

Connection establishment

Use a standard WebSocket client:
The connection can close when you disconnect, fail to answer heartbeats, encounter a network interruption, or the server restarts. Subscription continuity exhaustion can also close the connection. Core does not authenticate the incoming client; protect this endpoint at your deployment boundary.

Heartbeats

Most WebSocket libraries, including browsers, automatically answer control-frame pings. You do not need to send JSON-RPC messages to keep the connection alive. Browser JavaScript does not expose ping/pong control frames. A pong resets the missed-heartbeat count. If a client never answers, the nominal timeline is:
That is approximately 40 seconds from the first unanswered ping, or 70 seconds from a new connection that never responds. Scheduling and network delays can affect the observed times. Lasso answers client-initiated pings with pongs. Those pings do not substitute for answering the server’s own pings.

Idle timeout and session duration

The WebSocket transport has a two-hour idle timeout. It is not a maximum session lifetime: responsive connections can remain open beyond two hours. Traffic, including heartbeat replies, prevents an idle connection from reaching that timeout. Reconnect whenever the connection closes. Do not rely on a periodic two-hour disconnect or a particular idle-timeout close message.

Connection closure

These application-level closure cases have explicit meanings: A JSON-RPC rate-limit error can be returned on an open connection. It does not inherently mean the socket closes with code 1008. Deployments, access changes, proxies, and network failures can produce other close events; handle closure regardless of code. The released Core socket does not promise a dedicated slow-client close code. Bound your own processing and subscription volume, reconnect with capped backoff, and reconcile missed events after any closure.

Reconnection

Reconnect with capped exponential backoff and jitter, then recreate the subscriptions your application still needs. Subscription IDs belong to the old connection and must be replaced with the new IDs returned by eth_subscribe. This Node.js example uses the ws package and subscribes to new heads after each connection:
Recreating a subscription does not replay every event missed while your client was disconnected. Track your last processed block and use historical RPC reads to reconcile gaps where your application requires them.

Subscription cleanup

When your socket closes, Lasso detaches its logical subscriptions and releases their resources. Shared upstream streams can remain open for other clients or internal monitoring; disconnecting one client must not interrupt them. Use eth_unsubscribe when you no longer need an individual subscription. Closing the socket also cleans up its subscriptions; you do not need to wait for asynchronous unsubscribe calls during page unload.

Operating guidance

  • Let your WebSocket library answer pings promptly; avoid blocking its event loop.
  • Treat a long gap in notifications separately from a failed connection. A healthy stream may have no matching events.
  • Track reconnect frequency, subscription errors, and the last processed block.
  • Expect reconnects during deployments and network changes.
  • If a profile or provider configuration changes, inspect the active routes before repeatedly retrying.