dotnet/runtime · error · Error
No active JS diagnostic session
Error message
No active JS diagnostic session
What it means
collectMetrics() throws at its guard when called (startup=false) and serverSession is undefined. The diagnostic server inside the dotnet VM must have already advertised a session (setting serverSession) before counters can be collected. Same precondition as error 113 but checked locally in dotnet-counters.ts.
Solutions
- Await dotnet.create() then verify the diagnostics JS module loaded (resources.jsModuleDiagnostics non-empty).
- Pass startup=true to register the client at boot: collectMetrics({}, true) — this bypasses the serverSession check.
- Set DOTNET_DiagnosticPorts=js://ready so the runtime opens a JS session.
- Re-check after runtime exit; do not call collectors on a dead runtime.
Example fix
// before collectMetrics(); // serverSession undefined // after: register as startup client or wait const runtime = await dotnet.create(); await collectMetrics(); // session exists after first advert
Defensive patterns
Strategy: validation
Validate before calling
function canCollectMetrics(): boolean {
// serverSession exported from diagnostic-server-js
return !!serverSession;
} Type guard
function isSessionReady(): boolean { return !!serverSession; } Try / catch
try { await collectMetrics(); } catch (e) {
if (/No active JS diagnostic session/.test((e as Error).message)) {
collectMetrics({}, true); // register at startup slot, then create runtime
await dotnet.create();
} else throw e;
} Prevention
- Await dotnet.create() before calling collectMetrics().
- Confirm jsModuleDiagnostics is present in the boot config (diagnostics module linked).
- Use startup=true to register the client before runtime ready.
- Gate collector UI behind a runtime-ready state.
When it happens
Trigger: Calling collectMetrics() before any advert arrived from the runtime. Calling it after the session closed and serverSession was cleared. Diagnostics module not loaded (jsModuleDiagnostics absent) so no session ever starts.
Common situations: Forgetting to enable diagnostics at build (diagnostics module not linked). Calling collectMetrics() too early in startup. Runtime exited before the call.
Related errors
- No active JS diagnostic session
- Diag module already loaded
- No active JS diagnostic session
- No active session to reconnect
- Runtime is not running
AI-assisted analysis of dotnet/runtime@60108ba66e (2026-08-10).
Data as JSON: /api/errors/5d4703442ac1e2e4.
Report an issue: GitHub.
Appendix: source
Thrown at src/native/libs/System.Native.Browser/diagnostics/dotnet-counters.ts:14
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
import type { DiagnosticCommandOptions } from "../types";
import { commandResumeRuntime, commandStopTracing, commandCounters } from "./client-commands";
import { dotnetLoaderExports, Module } from "./cross-module";
import { serverSession, setupJsClient } from "./diagnostic-server-js";
import { IDiagnosticSession } from "./types";
export function collectMetrics(options?: DiagnosticCommandOptions, startup?: boolean): Promise<Uint8Array[]> {
if (!options) options = {};
if (!startup && !serverSession) {
throw new Error("No active JS diagnostic session");
}
const onClosePromise = dotnetLoaderExports.createPromiseCompletionSource<Uint8Array[]>();
function onSessionStart(session: IDiagnosticSession): void {
session.sendCommand(commandResumeRuntime());
// stop tracing after period of monitoring
Module.safeSetTimeout(() => {
session.sendCommand(commandStopTracing(session.sessionId));
}, 1000 * (options?.durationSeconds ?? 60));
}
setupJsClient({
onClosePromise: onClosePromise,
skipDownload: options.skipDownload,
commandOnAdvertise: () => commandCounters(options),
onSessionStart,
}, startup);
return onClosePromise.promise;
}View on GitHub (pinned to 60108ba66e)