dotnet/runtime · error · Error

No active JS diagnostic session

Error message

No active JS diagnostic session

What it means

Thrown by collectGcDump() (dotnet-gcdump) in diagnostics/dotnet-gcdump.ts when serverSession is undefined. Like the other collectors it requires an established in-browser diagnostic server session to send the GcHeapDump command and receive heap data.

Source

Thrown at src/mono/browser/runtime/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 { commandStopTracing, commandGcHeapDump, } from "./client-commands";
import { IDiagnosticSession } from "./common";
import { loaderHelpers, Module } from "./globals";
import { serverSession, setupJsClient } from "./diagnostics-js";

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

    const onClosePromise = loaderHelpers.createPromiseController<Uint8Array[]>();
    let stopDelayedAfterLastMessage = 0;
    let stopSent = false;
    function onData (session: IDiagnosticSession, message: Uint8Array): void {
        session.store(message);
        if (!stopSent) {
            // stop 500ms after last GC message on this session, there will be more messages after that
            if (stopDelayedAfterLastMessage) {
                clearTimeout(stopDelayedAfterLastMessage);
                Module.runtimeKeepalivePop();
            }
            stopDelayedAfterLastMessage = Module.safeSetTimeout(() => {
                stopSent = true;
                session.sendCommand(commandStopTracing(session.session_id));
            }, 1000 * (options?.durationSeconds ?? 1));
        }

View on GitHub (pinned to 290d5ab72c)

Solutions

  1. Wait for the runtime to be ready and the diagnostic server to have advertised before collecting a gcdump.
  2. Enable diagnostics in the build and trigger a session (js://gcdump scenario or DOTNET_DiagnosticPorts).
  3. Confirm serverSession is established before calling collectGcDump.

Example fix

null
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

null

Try / catch

null

Prevention

When it happens

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

Common situations: Capturing a gcdump too early at startup. A build/configuration that did not start the diagnostic server.

Related errors


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