{"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/290d5ab72cc1102813fbc0406fb186ceadabc340/src/mono/browser/runtime/diagnostics/index.ts#L66-L94","documentation":"Thrown by connectDSRouter() in diagnostics/index.ts when the module-level serverSession (from diagnostics-js.ts) is undefined. connectDSRouter is meant to take over an EXISTING in-browser diagnostic session and redirect it to a new dotnet-dsrouter WebSocket URL; it requires that a diagnostic server in the Mono VM has already advertised and established serverSession. With no current session there is nothing to reconnect.","triggerScenarios":"Calling API.connectDSRouter(url) before any diagnostic server advert has arrived (i.e. before serverSession was set in DiagnosticSession.send). Calling it after the session closed and serverSession was cleared.","commonSituations":"Wiring up dotnet-dsrouter (server-websocket) routing too early during startup, before the .NET diagnostic server advertised. Calling connectDSRouter in app code that runs before the runtime is ready.","solutions":["Ensure the runtime is initialized and the diagnostic server has advertised before calling connectDSRouter (wait for the runtime ready signal).","Use the standard diagnostic port configuration so a serverSession is created first, then call connectDSRouter to redirect it.","If the session was closed, start a fresh diagnostic session instead of trying to reconnect a non-existent one."],"exampleFix":"// before\nconnectDSRouter(\"ws://localhost:8181\"); // called at app start, no session yet\n\n// after\nawait dotnet.ready; // ensure runtime + diagnostic server advertised\nconnectDSRouter(\"ws://localhost:8181\");","handlingStrategy":"validation","validationCode":"import { serverSession } from \"./diagnostics-js\";\nfunction connectDSRouterSafe(url: string) {\n  if (!serverSession) {\n    throw new Error('connectDSRouter called before a diagnostic session exists; wait for the runtime to advertise a session.');\n  }\n  return connectDSRouter(url);\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Wait until the runtime is ready and a diagnostic session is advertised.","Configure a diagnostic port so a session is established first."],"tags":["diagnostics","dsrouter","ordering","session"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}