dotnet/runtime · error · Error
No active session to reconnect
Error message
No active session to reconnect
What it means
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.
Source
Thrown at src/native/libs/System.Native.Browser/diagnostics/diagnostic-server.ts:78
}
const bufferPtr: VoidPtr = buffer as any >>> 0 as any;
return wrapper.recv(bufferPtr, bytesToRead);
}
export function ds_rt_websocket_close(clientSocket: number): number {
const wrapper = socketHandles.get(clientSocket);
if (!wrapper) {
return -1;
}
socketHandles.delete(clientSocket);
return wrapper.close();
}
// this will take over the existing connection to JS and send new advert message to WS client
// use dotnet-dsrouter server-websocket -v trace
export function connectDSRouter(url: string): void {
if (!serverSession) {
throw new Error("No active session to reconnect");
}
// make sure new sessions hit the new URL
urlOverride = url;
const oldWrapper = socketHandles.get(serverSession.clientSocket);
if (oldWrapper) {
oldWrapper.close();
}
const wrapper = createDiagConnectionWs(serverSession.clientSocket, url);
socketHandles.set(serverSession.clientSocket, wrapper);
wrapper.send(advertise());
}
export function initializeDS() {
const loaderConfig = dotnetApi.getConfig();
const diagnosticPorts = "DOTNET_DiagnosticPorts";
loaderConfig.environmentVariables ??= {};View on GitHub (pinned to 290d5ab72c)
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.
Example fix
// before: reconnecting before any session exists runtimeStarted.then(() => dotnetApi.connectDSRouter(wsUrl)); // throws if no session // after: wait for a session, then reconnect runtimeSessionReady.then(() => dotnetApi.connectDSRouter(wsUrl));
Defensive patterns
Strategy: validation
Validate before calling
// Only hand off to a DSRouter once a session exists
import { serverSession } from './diagnostic-server-js';
if (!serverSession) {
throw new Error('No diagnostic session yet; start the runtime with DOTNET_DiagnosticPorts set before calling connectDSRouter.');
}
dotnetApi.connectDSRouter(wsUrl); Prevention
- 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.
When it happens
Trigger: Calling connectDSRouter(url) before the diagnostic server has accepted a session and assigned serverSession.
Common situations: Wiring up dotnet-dsrouter before the runtime emitted an advert; calling connectDSRouter too early in init; diagnostics not enabled so no session ever starts.
Related errors
- No active session to reconnect
- No active JS diagnostic session
- No active JS diagnostic session
- No active JS diagnostic session
- No active JS diagnostic session
AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06).
Data as JSON: /api/errors/b6b60717592ceb3f.
Report an issue: GitHub.