{"record":{"id":"b6b60717592ceb3f","repo":"dotnet/runtime","slug":"no-active-session-to-reconnect-b6b607","errorCode":null,"errorMessage":"No active session to reconnect","messagePattern":"No active session to reconnect","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/native/libs/System.Native.Browser/diagnostics/diagnostic-server.ts","lineNumber":78,"sourceCode":"    }\n    const bufferPtr: VoidPtr = buffer as any >>> 0 as any;\n    return wrapper.recv(bufferPtr, bytesToRead);\n}\n\nexport function ds_rt_websocket_close(clientSocket: number): number {\n    const wrapper = socketHandles.get(clientSocket);\n    if (!wrapper) {\n        return -1;\n    }\n    socketHandles.delete(clientSocket);\n    return wrapper.close();\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\nexport function 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    urlOverride = url;\n\n    const oldWrapper = socketHandles.get(serverSession.clientSocket);\n    if (oldWrapper) {\n        oldWrapper.close();\n    }\n    const wrapper = createDiagConnectionWs(serverSession.clientSocket, url);\n    socketHandles.set(serverSession.clientSocket, wrapper);\n    wrapper.send(advertise());\n}\n\nexport function initializeDS() {\n    const loaderConfig = dotnetApi.getConfig();\n    const diagnosticPorts = \"DOTNET_DiagnosticPorts\";\n    loaderConfig.environmentVariables ??= {};","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/native/libs/System.Native.Browser/diagnostics/diagnostic-server.ts#L60-L96","documentation":"Thrown by connectDSRouter when serverSession is undefined. connectDSRouter hands off an existing JS diagnostic session to a WebSocket dotnet-dsrouter connection; it needs a live session to take over, so calling it before any session exists is invalid.","triggerScenarios":"Calling connectDSRouter(url) before the diagnostic server has accepted a session and assigned serverSession.","commonSituations":"Wiring up dotnet-dsrouter before the runtime emitted an advert; calling connectDSRouter too early in init; diagnostics not enabled so no session ever starts.","solutions":["Call connectDSRouter only after a diagnostic session has been established (after the runtime is running and has advertised).","Ensure DOTNET_DiagnosticPorts is configured so the diagnostic server creates a session."],"exampleFix":"// before: reconnecting before any session exists\nruntimeStarted.then(() => dotnetApi.connectDSRouter(wsUrl)); // throws if no session\n// after: wait for a session, then reconnect\nruntimeSessionReady.then(() => dotnetApi.connectDSRouter(wsUrl));","handlingStrategy":"validation","validationCode":"// Only hand off to a DSRouter once a session exists\nimport { serverSession } from './diagnostic-server-js';\nif (!serverSession) {\n  throw new Error('No diagnostic session yet; start the runtime with DOTNET_DiagnosticPorts set before calling connectDSRouter.');\n}\ndotnetApi.connectDSRouter(wsUrl);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call connectDSRouter only after the diagnostic server has created a session.","Confirm DOTNET_DiagnosticPorts is configured before attempting a reconnect.","Order startup so the DSRouter hand-off happens post-advert."],"tags":["diagnostics","dsrouter","session","ordering"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}