{"record":{"id":"cd9b020248d61544","repo":"dotnet/runtime","slug":"no-active-js-diagnostic-session-cd9b02","errorCode":null,"errorMessage":"No active JS diagnostic session","messagePattern":"No active JS diagnostic session","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/native/libs/System.Native.Browser/diagnostics/dotnet-gcdump.ts","lineNumber":14,"sourceCode":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n\nimport type { DiagnosticCommandOptions } from \"../types\";\n\nimport { commandResumeRuntime, commandStopTracing, commandGcHeapDump, } from \"./client-commands\";\nimport { dotnetLoaderExports, Module } from \"./cross-module\";\nimport { serverSession, setupJsClient } from \"./diagnostic-server-js\";\nimport { IDiagnosticSession } from \"./types\";\n\nexport function collectGcDump(options?: DiagnosticCommandOptions, startup?: boolean): Promise<Uint8Array[]> {\n    if (!options) options = {};\n    if (!startup && !serverSession) {\n        throw new Error(\"No active JS diagnostic session\");\n    }\n\n    const onClosePromise = dotnetLoaderExports.createPromiseCompletionSource<Uint8Array[]>();\n    let stopDelayedAfterLastMessage = 0;\n    let stopSent = false;\n    function onSessionStart(session: IDiagnosticSession): void {\n        session.sendCommand(commandResumeRuntime());\n    }\n    function onData(session: IDiagnosticSession, message: Uint8Array): void {\n        session.store(message);\n        if (!stopSent) {\n            // stop durationSeconds (default 1s) after last GC message on this session, there will be more messages after that\n            if (stopDelayedAfterLastMessage) {\n                clearTimeout(stopDelayedAfterLastMessage);\n            }\n            stopDelayedAfterLastMessage = Module.safeSetTimeout(() => {\n                stopSent = true;\n                session.sendCommand(commandStopTracing(session.sessionId));","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/native/libs/System.Native.Browser/diagnostics/dotnet-gcdump.ts#L1-L32","documentation":"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.","triggerScenarios":"collectGcDump() invoked after runtime start but before the diagnostic server completed a session handshake (serverSession undefined).","commonSituations":"Calling gcdump before the runtime/session is ready; diagnostics disabled; missing DOTNET_DiagnosticPorts.","solutions":["Ensure the runtime is running and DOTNET_DiagnosticPorts is configured so a JS session exists.","Use collectGcDump(opts, true) to capture a heap dump at startup.","Call collectGcDump only after a diagnostic session is established."],"exampleFix":"// before: runtime gcdump with no session\ncollectGcDump(); // throws\n// after: register at startup\ncollectGcDump({ durationSeconds: 5 }, true);","handlingStrategy":"validation","validationCode":"// Verify a session exists (or use startup) before collecting a gcdump\nimport { serverSession } from './diagnostic-server-js';\nif (!serverSession) {\n  collectGcDump({ durationSeconds: 5 }, true);\n} else {\n  collectGcDump({ durationSeconds: 5 });\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the startup=true path for boot-time heap dumps.","Ensure DOTNET_DiagnosticPorts creates a session before runtime gcdump.","Gate runtime collect calls on a known session state."],"tags":["diagnostics","gcdump","session","ordering"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}