dotnet/runtime · error · Error
No active JS diagnostic session
Error message
No active JS diagnostic session
What it means
collectCpuSamples() has the identical guard as collectMetrics: it throws when startup=false and serverSession is undefined. CPU sampling needs an active diagnostic session to deliver SampleProfiler commands. The check fires before the WasmPerformanceInstrumentation check (error 119), so sessions must be active first.
Solutions
- Await runtime creation: const rt = await dotnet.create(); await collectCpuSamples();
- Use startup=true to register before boot: collectCpuSamples({}, true) — note you still need WasmPerformanceInstrumentation enabled (else 119).
- Confirm resources.jsModuleDiagnostics is present in the boot config.
- If runtime exited, restart it before sampling.
Example fix
// before
collectCpuSamples(); // serverSession undefined
// after
await dotnet.create();
await collectCpuSamples({ durationSeconds: 30 }); Defensive patterns
Strategy: validation
Validate before calling
function canCollectCpuSamples(): boolean {
return !!serverSession
&& !!dotnetApi.getConfig().environmentVariables?.['DOTNET_WasmPerformanceInstrumentation'];
} Type guard
function isSessionReady(): boolean { return !!serverSession; } Try / catch
try { await collectCpuSamples(); } catch (e) {
if (/No active JS diagnostic session/.test((e as Error).message)) {
await dotnet.create();
await collectCpuSamples();
} else throw e;
} Prevention
- Await dotnet.create() before invoking collectCpuSamples().
- Ensure the diagnostics JS module is bundled (resources.jsModuleDiagnostics non-empty).
- Use startup=true when profiling from boot.
- Detect a dead runtime and stop offering the profiling action.
When it happens
Trigger: Calling collectCpuSamples() before runtime ready, before any advert, or after session close. Same as 117 but for the cpu profiler entry point.
Common situations: Profiling from a UI button before runtime finished booting. Diagnostics module not included in the build. Runtime crashed and session was torn down.
Related errors
- No active JS diagnostic session
- Diag module already loaded
- method instrumentation is not enabled, please enable it…
- No active JS diagnostic session
- No active session to reconnect
AI-assisted analysis of dotnet/runtime@60108ba66e (2026-08-10).
Data as JSON: /api/errors/830d58b060637d62.
Report an issue: GitHub.
Appendix: 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 60108ba66e)