dotnet/runtime · error · Error

No active JS diagnostic session

Error message

No active JS diagnostic session

What it means

Thrown by collectGcDump (dotnet-gcdump) when called at runtime (startup=false) but serverSession is undefined: no JS diagnostic session exists to attach the gcdump client to. Same precondition as the counters/cpu variants, scoped to heap dumps.

Source

Thrown at src/native/libs/System.Native.Browser/diagnostics/dotnet-gcdump.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, commandGcHeapDump, } from "./client-commands";
import { dotnetLoaderExports, Module } from "./cross-module";
import { serverSession, setupJsClient } from "./diagnostic-server-js";
import { IDiagnosticSession } from "./types";

export function collectGcDump(options?: DiagnosticCommandOptions, startup?: boolean): Promise<Uint8Array[]> {
    if (!options) options = {};
    if (!startup && !serverSession) {
        throw new Error("No active JS diagnostic session");
    }

    const onClosePromise = dotnetLoaderExports.createPromiseCompletionSource<Uint8Array[]>();
    let stopDelayedAfterLastMessage = 0;
    let stopSent = false;
    function onSessionStart(session: IDiagnosticSession): void {
        session.sendCommand(commandResumeRuntime());
    }
    function onData(session: IDiagnosticSession, message: Uint8Array): void {
        session.store(message);
        if (!stopSent) {
            // stop durationSeconds (default 1s) after last GC message on this session, there will be more messages after that
            if (stopDelayedAfterLastMessage) {
                clearTimeout(stopDelayedAfterLastMessage);
            }
            stopDelayedAfterLastMessage = Module.safeSetTimeout(() => {
                stopSent = true;
                session.sendCommand(commandStopTracing(session.sessionId));

View on GitHub (pinned to 290d5ab72c)

Solutions

  1. Ensure the runtime is running and DOTNET_DiagnosticPorts is configured so a JS session exists.
  2. Use collectGcDump(opts, true) to capture a heap dump at startup.
  3. Call collectGcDump only after a diagnostic session is established.

Example fix

// before: runtime gcdump with no session
collectGcDump(); // throws
// after: register at startup
collectGcDump({ durationSeconds: 5 }, true);
Defensive patterns

Strategy: validation

Validate before calling

// Verify a session exists (or use startup) before collecting a gcdump
import { serverSession } from './diagnostic-server-js';
if (!serverSession) {
  collectGcDump({ durationSeconds: 5 }, true);
} else {
  collectGcDump({ durationSeconds: 5 });
}

Prevention

When it happens

Trigger: collectGcDump() invoked after runtime start but before the diagnostic server completed a session handshake (serverSession undefined).

Common situations: Calling gcdump before the runtime/session is ready; diagnostics disabled; missing DOTNET_DiagnosticPorts.

Related errors


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