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) in diagnostics/dotnet-cpu-profiler.ts when serverSession is undefined. Same precondition as the other collectors: an in-browser diagnostic server session must already exist for the profiler to send its sampling commands.

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 290d5ab72c)

Solutions

  1. Ensure the runtime is ready and the diagnostic server has established a session before profiling.
  2. Enable diagnostics in the build and trigger a session (js://cpu-samples scenario or DOTNET_DiagnosticPorts).
  3. Wait for serverSession to be non-null (the advertise handshake) before calling collectCpuSamples.

Example fix

null
Defensive patterns

Strategy: validation

Validate before calling

import { serverSession } from "./diagnostics-js";
async function collectCpuSamplesSafe(opts?: DiagnosticCommandOptions) {
  if (!serverSession) throw new Error('No diagnostic session yet; start one before profiling.');
  return collectCpuSamples(opts);
}

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Calling API.collectCpuSamples() before the .NET diagnostic server advertised, or when diagnostics were not enabled.

Common situations: Profiling too early at startup. A build without the diagnostic server. Diagnostics disabled via configuration.

Related errors


AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06). Data as JSON: /api/errors/822d9aca775761fa. Report an issue: GitHub.