You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is often the case that Polygon Edge will sit behind a load balancer, reverse proxy, or other similar upstream infrastructure including NATs and firewalls. In this case, to protect the server, upstream infrastructure will usually have some sort of idle or network timeouts. This helps prevent the downstream server from hitting connection limits and ultimately protects the origin.
For WebSockets, since connections are long lived, they can often become stale if they are just using eth_subscribe for example. The solution to this without messing with the network level / proxy level parameters for idle timeouts and such is usually to have a client-initiated ping-pong mechanism. At the very simplest level, the server would respond with "pong" every time the client sends "ping"
Edge currently doesn't have this functionality, but it would be useful to help edge nodes stay safe in case they are handling large amounts of WebSocket connections.
import{Networkish}from"@ethersproject/providers";import{WebSocketLike}from"@ethersproject/providers/lib/websocket-provider";import{WebSocketProvider}from"@ethersproject/providers";constKEEP_ALIVE_CHECK_INTERVAL=10000;exportclassPingWebSocketProviderextendsWebSocketProvider{publickeepAliveInterval: number|null=null;constructor(url: string|WebSocketLike,network?: Networkish){super(url,network);this.websocket.onopen=()=>{this.keepAliveInterval=setInterval(()=>{this.websocket.send(JSON.stringify({jsonrpc: "2.0",method: "eth_chainId",params: [],id: 1}));// supposed to be the canonical "ping" message},KEEP_ALIVE_CHECK_INTERVAL)asany;};// Add functionality to support pong this._websocket.onclose=()=>{if(this.keepAliveInterval){clearInterval(this.keepAliveInterval);this.keepAliveInterval=null;}};}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
It is often the case that Polygon Edge will sit behind a load balancer, reverse proxy, or other similar upstream infrastructure including NATs and firewalls. In this case, to protect the server, upstream infrastructure will usually have some sort of idle or network timeouts. This helps prevent the downstream server from hitting connection limits and ultimately protects the origin.
For WebSockets, since connections are long lived, they can often become stale if they are just using
eth_subscribe
for example. The solution to this without messing with the network level / proxy level parameters for idle timeouts and such is usually to have a client-initiated ping-pong mechanism. At the very simplest level, the server would respond with "pong" every time the client sends "ping"Edge currently doesn't have this functionality, but it would be useful to help edge nodes stay safe in case they are handling large amounts of WebSocket connections.
Examples
server-side managed (more advanced): https://docs.deribit.com/#public-set_heartbeat
simple: Pure client side:
Beta Was this translation helpful? Give feedback.
All reactions