dotnet/runtime · error · Error
No active JS diagnostic session
Error message
No active JS diagnostic session
What it means
Thrown by collectMetrics() (dotnet-counters) in diagnostics/dotnet-counters.ts when serverSession is undefined. collectMetrics drives a dotnet-counters trace by talking to the in-browser .NET diagnostic server via the JS IPC channel; it needs an established DiagnosticSession. Without serverSession there is no diagnostic server to send the StartTracing/counters command to.
Source
Thrown at src/mono/browser/runtime/diagnostics/dotnet-counters.ts:15
// 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 { commandStopTracing, commandCounters } from "./client-commands";
import { IDiagnosticSession } from "./common";
import { Module } from "./globals";
import { serverSession, setupJsClient } from "./diagnostics-js";
import { loaderHelpers } from "./globals";
export function collectMetrics (options?:DiagnosticCommandOptions):Promise<Uint8Array[]> {
if (!options) options = {};
if (!serverSession) {
throw new Error("No active JS diagnostic session");
}
const onClosePromise = loaderHelpers.createPromiseController<Uint8Array[]>();
function onSessionStart (session: IDiagnosticSession): void {
// stop tracing after period of monitoring
Module.safeSetTimeout(() => {
session.sendCommand(commandStopTracing(session.session_id));
}, 1000 * (options?.durationSeconds ?? 60));
}
setupJsClient({
onClosePromise:onClosePromise.promise_control,
skipDownload:options.skipDownload,
commandOnAdvertise:() => commandCounters(options),
onSessionStart,
});
return onClosePromise.promise;
}
View on GitHub (pinned to 290d5ab72c)
Solutions
- Wait for the runtime to be ready and the diagnostic server to advertise before calling collectMetrics.
- Ensure diagnostics are enabled in the build/config (diagnostic port configured, js-module-diagnostics loaded).
- Trigger a diagnostic session first (e.g. via the js://counters scenario URL or DOTNET_DiagnosticPorts) so serverSession exists.
Example fix
null
Defensive patterns
Strategy: validation
Validate before calling
import { serverSession } from "./diagnostics-js";
async function collectMetricsSafe(opts?: DiagnosticCommandOptions) {
if (!serverSession) {
throw new Error('No diagnostic session yet; ensure the runtime is ready and diagnostics enabled before calling collectMetrics.');
}
return collectMetrics(opts);
} Type guard
null
Try / catch
null
Prevention
- Enable diagnostics in the build and trigger a session before collecting.
- Call collectors only after the runtime is ready.
When it happens
Trigger: Calling API.collectMetrics() before the .NET diagnostic server has advertised (serverSession set in DiagnosticSession.send), or when diagnostics were not enabled for the runtime.
Common situations: Calling collectMetrics during early startup before the diagnostic server is up. A release build or configuration that did not start the diagnostic server (no diagnostic port configured).
Related errors
- No active session to reconnect
- No active JS diagnostic session
- No active JS diagnostic session
- No active session to reconnect
- No active JS diagnostic session
AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06).
Data as JSON: /api/errors/2c59cd9af0f0a8c1.
Report an issue: GitHub.