{"record":{"id":"33927b221674321d","repo":"dotnet/runtime","slug":"no-active-js-diagnostic-session-33927b","errorCode":null,"errorMessage":"No active JS diagnostic session","messagePattern":"No active JS diagnostic session","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/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 { commandStopTracing, commandGcHeapDump, } from \"./client-commands\";\nimport { IDiagnosticSession } from \"./common\";\nimport { loaderHelpers, Module } from \"./globals\";\nimport { serverSession, setupJsClient } from \"./diagnostics-js\";\n\nexport function collectGcDump (options?:DiagnosticCommandOptions):Promise<Uint8Array[]> {\n    if (!options) options = {};\n    if (!serverSession) {\n        throw new Error(\"No active JS diagnostic session\");\n    }\n\n    const onClosePromise = loaderHelpers.createPromiseController<Uint8Array[]>();\n    let stopDelayedAfterLastMessage = 0;\n    let stopSent = false;\n    function onData (session: IDiagnosticSession, message: Uint8Array): void {\n        session.store(message);\n        if (!stopSent) {\n            // stop 500ms after last GC message on this session, there will be more messages after that\n            if (stopDelayedAfterLastMessage) {\n                clearTimeout(stopDelayedAfterLastMessage);\n                Module.runtimeKeepalivePop();\n            }\n            stopDelayedAfterLastMessage = Module.safeSetTimeout(() => {\n                stopSent = true;\n                session.sendCommand(commandStopTracing(session.session_id));\n            }, 1000 * (options?.durationSeconds ?? 1));\n        }","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/mono/browser/runtime/diagnostics/dotnet-gcdump.ts#L1-L32","documentation":"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.","triggerScenarios":"Calling API.collectGcDump() before the .NET diagnostic server advertised, or when diagnostics were not enabled in the build.","commonSituations":"Capturing a gcdump too early at startup. A build/configuration that did not start the diagnostic server.","solutions":["Wait for the runtime to be ready and the diagnostic server to have advertised before collecting a gcdump.","Enable diagnostics in the build and trigger a session (js://gcdump scenario or DOTNET_DiagnosticPorts).","Confirm serverSession is established before calling collectGcDump."],"exampleFix":"null","handlingStrategy":"validation","validationCode":"import { serverSession } from \"./diagnostics-js\";\nasync function collectGcDumpSafe(opts?: DiagnosticCommandOptions) {\n  if (!serverSession) throw new Error('No diagnostic session yet; start one before capturing a gcdump.');\n  return collectGcDump(opts);\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Establish a diagnostic session before capturing a gcdump.","Call only after the runtime is ready."],"tags":["diagnostics","dotnet-gcdump","session","ordering"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}