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 called at runtime (startup=false) but serverSession is undefined: no JS diagnostic session exists to attach the CPU-sampling client to. Identical precondition to the counters variant, scoped to the CPU profiler.
Source
Thrown at src/native/libs/System.Native.Browser/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 { commandResumeRuntime, commandStopTracing, commandSampleProfiler } from "./client-commands";
import { dotnetApi, dotnetLoaderExports, Module } from "./cross-module";
import { serverSession, setupJsClient } from "./diagnostic-server-js";
import { IDiagnosticSession } from "./types";
export function collectCpuSamples(options?: DiagnosticCommandOptions, startup?: boolean): Promise<Uint8Array[]> {
if (!options) options = {};
if (!startup && !serverSession) {
throw new Error("No active JS diagnostic session");
}
if (!dotnetApi.getConfig().environmentVariables!["DOTNET_WasmPerformanceInstrumentation"]) {
throw new Error("method instrumentation is not enabled, please enable it with WasmPerformanceInstrumentation MSBuild property");
}
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: () => commandSampleProfiler(options),View on GitHub (pinned to 290d5ab72c)
Solutions
- Ensure the runtime is running and DOTNET_DiagnosticPorts is configured so a JS session exists.
- Use collectCpuSamples(opts, true) to sample from startup.
- Call collectCpuSamples only after a diagnostic session is established.
Example fix
// before: runtime CPU profiling with no session
collectCpuSamples(); // throws
// after: register at startup
collectCpuSamples({ durationSeconds: 30 }, true); Defensive patterns
Strategy: validation
Validate before calling
// Verify a session exists (or use startup) before CPU sampling
import { serverSession } from './diagnostic-server-js';
import { dotnetApi } from './cross-module';
if (!dotnetApi.getConfig().environmentVariables?.DOTNET_WasmPerformanceInstrumentation) {
throw new Error('Enable WasmPerformanceInstrumentation before profiling.');
}
if (!serverSession) collectCpuSamples({ durationSeconds: 30 }, true);
else collectCpuSamples({ durationSeconds: 30 }); Prevention
- Enable <WasmPerformanceInstrumentation>true</WasmPerformanceInstrumentation> before relying on CPU sampling.
- Use the startup=true path for from-boot CPU samples.
- Confirm DOTNET_DiagnosticPorts creates a session before runtime collection.
When it happens
Trigger: collectCpuSamples() invoked after runtime start but before the diagnostic server completed a session handshake (serverSession undefined).
Common situations: Calling the profiler before the runtime/session is ready; diagnostics disabled; missing DOTNET_DiagnosticPorts.
Related errors
- No active session to reconnect
- No active JS diagnostic session
- No active JS diagnostic session
- No active JS diagnostic session
- No active session to reconnect
AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06).
Data as JSON: /api/errors/830d58b060637d62.
Report an issue: GitHub.