dotnet/runtime · error · Error
No active JS diagnostic session
Error message
No active JS diagnostic session
What it means
Thrown by `collectCpuSamples` (dotnet-cpu-profiler) when no JS diagnostic session exists. Same precondition as the counters collector: the runtime must have advertised a session so the profiler can send its StartSampling command over the established transport.
Solutions
- Defer `collectCpuSamples` until the runtime is ready and `serverSession` exists.
- Publish the runtime with diagnostics enabled.
- Confirm `DOTNET_DiagnosticPorts` is configured to expose the JS transport.
Example fix
// before: called before session
const s = collectCpuSamples({}); // throws
// after: wait for the diagnostic session
await waitForDiagSession();
const s = collectCpuSamples({ durationSeconds: 5 }); Defensive patterns
Strategy: validation
Validate before calling
function canCollectCpuSamples () {
return !!serverSession;
}
if (canCollectCpuSamples()) collectCpuSamples({ durationSeconds: 5 }); Type guard
function hasActiveDiagSession (): boolean {
return typeof serverSession !== 'undefined' && serverSession !== null;
} Prevention
- Defer profiling until the diagnostic session is established.
- Enable diagnostics in the published runtime.
- Surface the profiler UI only after the runtime is ready.
When it happens
Trigger: Calling `collectCpuSamples(options)` (dotnet-cpu-profiler.ts:11) before `serverSession` is set. Occurs when the profiler is invoked at startup, when the runtime has no diagnostics enabled, or before the advert handshake completes.
Common situations: Profiling before runtime ready; runtime published without the diagnostics module; misconfigured diagnostic ports.
Related errors
- No active JS diagnostic session
- No active JS diagnostic session
- Failed on mono_wasm_get_dbg_command_info
- method instrumentation is not enabled, please enable it…
- multiple clients in parallel are not allowed
AI-assisted analysis of dotnet/runtime@60108ba66e (2026-08-10).
Data as JSON: /api/errors/822d9aca775761fa.
Report an issue: GitHub.
Appendix: source
Thrown at src/mono/browser/runtime/diagnostics/dotnet-cpu-profiler.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 { commandStopTracing, commandSampleProfiler } from "./client-commands";
import { loaderHelpers, Module, runtimeHelpers } from "./globals";
import { serverSession, setupJsClient } from "./diagnostics-js";
import { IDiagnosticSession } from "./common";
export function collectCpuSamples (options?:DiagnosticCommandOptions):Promise<Uint8Array[]> {
if (!options) options = {};
if (!serverSession) {
throw new Error("No active JS diagnostic session");
}
if (!runtimeHelpers.config.environmentVariables!["DOTNET_WasmPerformanceInstrumentation"]) {
throw new Error("method instrumentation is not enabled, please enable it with WasmPerformanceInstrumentation MSBuild property");
}
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: () => commandSampleProfiler(options),
onSessionStart,View on GitHub (pinned to 60108ba66e)