{"record":{"id":"443f26f7eda54bd9","repo":"dotnet/runtime","slug":"no-active-session-to-reconnect","errorCode":null,"errorMessage":"No active session to reconnect","messagePattern":"No active session to reconnect","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/diagnostics/index.ts","lineNumber":84,"sourceCode":"            return -1;\n        }\n        socket_handles.delete(client_socket);\n        return wrapper.close();\n    };\n\n    globalObjects.api.collectCpuSamples = collectCpuSamples;\n    globalObjects.api.collectMetrics = collectMetrics;\n    globalObjects.api.collectGcDump = collectGcDump;\n    globalObjects.api.connectDSRouter = connectDSRouter;\n\n    cleanup_js_client();\n}\n\n// this will take over the existing connection to JS and send new advert message to WS client\n// use dotnet-dsrouter server-websocket -v trace\nfunction connectDSRouter (url: string): void {\n    if (!serverSession) {\n        throw new Error(\"No active session to reconnect\");\n    }\n\n    // make sure new sessions hit the new URL\n    url_override = url;\n\n    const wrapper = createDiagConnectionWs(serverSession.client_socket, url);\n    socket_handles.set(serverSession.client_socket, wrapper);\n    wrapper.send(advertise());\n}\n","sourceCodeStart":66,"sourceCodeEnd":94,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/mono/browser/runtime/diagnostics/index.ts#L66-L94","documentation":"Thrown by `connectDSRouter` when there is no existing `serverSession` to migrate. The function's purpose is to take over an already established diagnostic session and redirect it to a new WebSocket URL (e.g. switching to dotnet-dsrouter); without a live session there is nothing to reconnect.","triggerScenarios":"Calling `connectDSRouter(url)` (index.ts:82) before the runtime has advertised a diagnostic session, or after the session was closed. The guard at index.ts:83-85 fires because `serverSession` is undefined.","commonSituations":"Calling `connectDSRouter` at startup before the advert arrives; calling it after the prior session ended; runtime published without diagnostics.","solutions":["Wait until `serverSession` exists (the runtime has advertised) before calling `connectDSRouter`.","Do not call `connectDSRouter` after the diagnostic session was closed; re-establish one first.","Ensure diagnostics are enabled in the runtime so an advert is produced."],"exampleFix":"// before: no session yet\nconnectDSRouter('ws://localhost:8080'); // throws\n\n// after: wait for the session, then switch the router\nawait waitForDiagSession();\nconnectDSRouter('ws://localhost:8080');","handlingStrategy":"validation","validationCode":"function canConnectDSRouter () {\n  return !!serverSession;\n}\nif (canConnectDSRouter()) connectDSRouter(url);","typeGuard":"function hasSessionToReconnect (): boolean {\n  return typeof serverSession !== 'undefined' && serverSession !== null;\n}","tryCatchPattern":null,"preventionTips":["Call `connectDSRouter` only after the runtime has advertised a session.","Do not call it after the diagnostic session was closed.","Enable diagnostics so an advert is produced."],"tags":["diagnostics","dsrouter","session-management","websocket"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}