dotnet/runtime · error · Error
Runtime is not running
Error message
Runtime is not running
What it means
Thrown by setupJsClient when called with startup=false while the .NET runtime is not yet running. Diagnostic clients (metrics, gcdump, cpu profiler) must attach either at startup (startup=true) or after the runtime is ready; attaching at runtime before readiness is invalid.
Source
Thrown at src/native/libs/System.Native.Browser/diagnostics/diagnostic-server-js.ts:150
if (this.messagesToSend.length === 0) {
return 0;
}
if (this.diagClient && !this.diagClient.skipDownload) {
downloadBlob(this.messagesToSend);
}
this.messagesToSend = [];
return 0;
}
}
export function initializeJsClient() {
nextJsClient = dotnetLoaderExports.createPromiseCompletionSource<IDiagnosticClient>();
startupJsClient = undefined;
}
export function setupJsClient(client: IDiagnosticClient, startup?: boolean) {
if (!startup && !dotnetLoaderExports.isRuntimeRunning()) {
throw new Error("Runtime is not running");
}
if (startup) {
if (startupJsClient) {
throw new Error("startup diagnostic client already registered");
}
startupJsClient = client;
} else {
if (nextJsClient.isDone) {
throw new Error("multiple clients in parallel are not allowed");
}
nextJsClient.resolve(client);
}
}
export function createDiagConnectionJs(socketHandle: number, scenarioName: string): DiagnosticSession {
if (!fromScenarioNameOnce) {
fromScenarioNameOnce = true;
if (scenarioName.startsWith("js://gcdump")) {View on GitHub (pinned to 290d5ab72c)
Solutions
- Wait for the runtime-ready signal before calling any runtime diagnostic collect function.
- If you need data from the very start, register the client at startup with collect*(opts, true).
Example fix
// before: collecting metrics before runtime ready Module.onRuntimeInitialized = () => collectMetrics(); // after: collect once the runtime reports running Module.onRuntimeInitialized = () => runtimeReady.then(() => collectMetrics());
Defensive patterns
Strategy: validation
Validate before calling
// Only attach a runtime diagnostic client once the runtime is running
if (!dotnetLoaderExports.isRuntimeRunning()) {
throw new Error('Runtime not ready; call collectMetrics after runtime-ready or use the startup hook.');
}
collectMetrics(); Prevention
- Await the runtime-ready signal before calling any runtime diagnostic API.
- Use the startup=true path for capture that must begin at boot.
- Surface a clear app-state gate so UI cannot trigger diagnostics pre-ready.
When it happens
Trigger: Calling collectMetrics()/collectGcDump()/collectCpuSamples() (without startup=true) before dotnetLoaderExports.isRuntimeRunning() returns true.
Common situations: Invoking diagnostics from an onRuntimeInitialized callback that fires before the runtime reports running; an app-init race where the button handler runs too early.
Related errors
- No active session to reconnect
- No active JS diagnostic session
- No active JS diagnostic session
- No active JS diagnostic session
- No active session to reconnect
AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06).
Data as JSON: /api/errors/b727cd6cde73b4c4.
Report an issue: GitHub.