dotnet/runtime · error · Error

No active session to reconnect

Error message

No active session to reconnect

What it means

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.

Source

Thrown at src/mono/browser/runtime/diagnostics/index.ts:84

            return -1;
        }
        socket_handles.delete(client_socket);
        return wrapper.close();
    };

    globalObjects.api.collectCpuSamples = collectCpuSamples;
    globalObjects.api.collectMetrics = collectMetrics;
    globalObjects.api.collectGcDump = collectGcDump;
    globalObjects.api.connectDSRouter = connectDSRouter;

    cleanup_js_client();
}

// this will take over the existing connection to JS and send new advert message to WS client
// use dotnet-dsrouter server-websocket -v trace
function connectDSRouter (url: string): void {
    if (!serverSession) {
        throw new Error("No active session to reconnect");
    }

    // make sure new sessions hit the new URL
    url_override = url;

    const wrapper = createDiagConnectionWs(serverSession.client_socket, url);
    socket_handles.set(serverSession.client_socket, wrapper);
    wrapper.send(advertise());
}

View on GitHub (pinned to 290d5ab72c)

Solutions

  1. Ensure the runtime is initialized and the diagnostic server has advertised before calling connectDSRouter (wait for the runtime ready signal).
  2. Use the standard diagnostic port configuration so a serverSession is created first, then call connectDSRouter to redirect it.
  3. If the session was closed, start a fresh diagnostic session instead of trying to reconnect a non-existent one.

Example fix

// before
connectDSRouter("ws://localhost:8181"); // called at app start, no session yet

// after
await dotnet.ready; // ensure runtime + diagnostic server advertised
connectDSRouter("ws://localhost:8181");
Defensive patterns

Strategy: validation

Validate before calling

import { serverSession } from "./diagnostics-js";
function connectDSRouterSafe(url: string) {
  if (!serverSession) {
    throw new Error('connectDSRouter called before a diagnostic session exists; wait for the runtime to advertise a session.');
  }
  return connectDSRouter(url);
}

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06). Data as JSON: /api/errors/443f26f7eda54bd9. Report an issue: GitHub.