{"record":{"id":"79fe806d0953dfc0","repo":"hcengineering/platform","slug":"ws-server-not-responding-to-ping-closing-connecti","errorCode":null,"errorMessage":"WS-server not responding to ping, closing connection","messagePattern":"WS-server not responding to ping, closing connection","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/hulypulse-client/src/client.ts","lineNumber":235,"sourceCode":"      this.send({ type: 'sub', key }).catch((error) => {\n        console.error(`Resubscription failed for key=${key}:`, error)\n        // throw new Error(`Resubscription failed for key=${key}: ${error.message ?? error}`)\n      })\n    }\n  }\n\n  private startPing (): void {\n    this.stopPing()\n    this.pingInterval = setInterval(() => {\n      if (this.ws?.readyState === WebSocket.OPEN) {\n        this.ws.send('ping')\n      }\n      if (this.pingTimeout !== undefined) {\n        clearTimeout(this.pingTimeout)\n      }\n      this.pingTimeout = setTimeout(() => {\n        if (this.ws?.readyState !== WebSocket.OPEN) {\n          console.warn('WS-server not responding to ping, closing connection')\n          clearInterval(this.pingInterval)\n          this.ws?.close(WS_CLOSE_NORMAL)\n        }\n      }, this.PING_TIMEOUT_MS)\n    }, this.PING_INTERVAL_MS)\n  }\n\n  private stopPing (): void {\n    if (this.pingInterval !== undefined) {\n      clearInterval(this.pingInterval)\n      this.pingInterval = undefined\n    }\n    if (this.pingTimeout !== undefined) {\n      clearTimeout(this.pingTimeout)\n      this.pingTimeout = undefined\n    }\n  }\n","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/packages/hulypulse-client/src/client.ts#L217-L253","documentation":"In startPing, the client sends pings on an interval and arms a PING_TIMEOUT_MS timer; if the socket is not OPEN when the timeout fires, it concludes the server never answered the ping, warns 'WS-server not responding to ping, closing connection', stops the ping interval, and closes the socket with WS_CLOSE_NORMAL. This is the client's keepalive/liveness mechanism detecting a dead or stalled connection.","triggerScenarios":"No pong (or no expected ping response) is received within PING_TIMEOUT_MS after a ping, or the WebSocket has left the OPEN state between pings.","commonSituations":"Server restart or crash; network blackholes (laptop sleep, NAT timeout, mobile network switch); overloaded WS server that stops responding to pings; firewall silently dropping idle connections.","solutions":["Check server availability/logs around the disconnect time - the server likely died or restarted.","Reduce network instability: keep-alives at the TCP/proxy level, avoid long idle periods behind NAT/load balancers.","After close, reconnect with exponential backoff (the client should resubscribe state on reconnect).","Tune PING_INTERVAL_MS / PING_TIMEOUT_MS if legitimate slow networks cause false positives."],"exampleFix":"// before\nthis.pingTimeout = setTimeout(() => {\n  if (this.ws?.readyState !== WebSocket.OPEN) {\n    console.warn('WS-server not responding to ping, closing connection')\n    clearInterval(this.pingInterval)\n    this.ws?.close(WS_CLOSE_NORMAL)\n  }\n}, this.PING_TIMEOUT_MS)\n// after\nthis.pingTimeout = setTimeout(() => {\n  if (this.ws?.readyState !== WebSocket.OPEN) {\n    console.warn('WS-server not responding to ping, closing connection')\n    clearInterval(this.pingInterval)\n    this.ws?.close(WS_CLOSE_NORMAL)\n    this.scheduleReconnect() // reconnect with backoff instead of staying closed\n  }\n}, this.PING_TIMEOUT_MS)","handlingStrategy":"retry","validationCode":"// Before relying on a connection, check readiness\nif (client.ws?.readyState !== WebSocket.OPEN) {\n  await client.reconnect()\n}\n","typeGuard":"function isOpen (ws: WebSocket | null | undefined): ws is WebSocket {\n  return ws != null && ws.readyState === WebSocket.OPEN\n}\n","tryCatchPattern":"try {\n  await client.send(msg)\n} catch (e) {\n  await backoffReconnect(client) // connection likely dead after ping timeout\n}\n","preventionTips":["Implement automatic reconnect with exponential backoff on close.","Tune PING_INTERVAL_MS/PING_TIMEOUT_MS for your network.","Monitor server uptime; ping timeouts usually mean server restarts or network drops."],"tags":["websocket","ping","keepalive","network","reconnect"],"backgroundTag":"websocket-ping-timeout","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}