{"record":{"id":"a250ab2256a295d3","repo":"cube-js/cube","slug":"socket-for-connectionid-is-not-found-found","errorCode":null,"errorMessage":"Socket for ${connectionId} is not found found","messagePattern":"Socket for (.+?) is not found found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/cubejs-server/src/websocket-server.ts","lineNumber":39,"sourceCode":"  protected subscriptionServer: SubscriptionServer | null = null;\n\n  public constructor(\n    protected readonly serverCore: CubejsServerCore,\n    protected readonly options: WebSocketServerOptions = {},\n  ) { }\n\n  public initServer(server: http.Server | https.Server) {\n    this.wsServer = new WebSocket.Server({\n      server,\n      path: this.options.webSocketsBasePath,\n      maxPayload: getEnv('maxRequestSize'),\n    });\n\n    const connectionIdToSocket: Record<string, any> = {};\n\n    this.subscriptionServer = this.serverCore.initSubscriptionServer(async (connectionId: string, message: any) => {\n      if (!connectionIdToSocket[connectionId]) {\n        throw new Error(`Socket for ${connectionId} is not found found`);\n      }\n\n      let messageStr: string;\n\n      if (message.message && message.message.isWrapper) {\n        // In case we have a wrapped query result, we don't want to parse/stringify\n        // it again - it's too expensive, instead we serialize the rest of the message and then\n        // inject query result json into message.\n        const resMsg = new TextDecoder().decode(await message.message.getFinalResult());\n        delete message.message;\n        messageStr = JSON.stringify(message);\n\n        if (messageStr === '{}') {\n          messageStr = `{\"message\":${resMsg}}`;\n        } else {\n          messageStr = `${messageStr.slice(0, -1)},\"message\":${resMsg}}`;\n        }\n      } else {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-server/src/websocket-server.ts#L21-L57","documentation":"Inside the websocket subscription server, the message-send callback looks up the active socket by connectionId in a local map; if the connection is missing it throws. The double 'found found' is a known typo in the message. This happens when Cube tries to deliver a message to a websocket connection that has already disconnected or was never registered in the map.","triggerScenarios":"A client disconnects while a subscription/query result is being pushed; the subscriptionServer invokes the send callback with a stale connectionId that no longer exists in connectionIdToSocket.","commonSituations":"Users closing the browser tab mid-query; flaky networks dropping WS connections while long-running queries complete; race between unsubscribe/cleanup and result delivery in apps using real-time dashboards.","solutions":["Upgrade to a fixed version of @cubejs-server/websocket-server if available (stale-connection race)","Treat this as a benign disconnect race: catch/log instead of letting it crash the callback","Ensure clients properly unsubscribe from subscriptions before closing connections","Check for proxies/load balancers with short WS idle timeouts causing premature disconnects"],"exampleFix":"// app-level guard: unsubscribe before close\nws.on('close', () => {\n  subscriptionIds.forEach(id => unsubscribe(id));\n});","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// wrap subscription message delivery client-side and server-side patch\ntry {\n  await sendMessage(connectionId, message);\n} catch (e) {\n  if (/Socket for .* is not found/.test(e.message)) {\n    // stale connection: client disconnected mid-query; log and unsubscribe\n    console.warn(`Stale connection ${connectionId}, dropping message`);\n    return;\n  }\n  throw e;\n}","preventionTips":["Unsubscribe from all subscriptions before closing websocket connections","Configure load balancers/proxies with generous WS idle timeouts","Reconnect clients with resubscribe logic (backoff + re-run active queries)","Track version notes for websocket-server fixes to stale-connection races"],"tags":["websocket","race-condition","realtime"],"backgroundTag":"websocket-connection-not-found","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}