{"record":{"id":"d9b7a1bb85a3452a","repo":"microsoft/aspire","slug":"cargo-metadata-for-the-rust-app-resourcename-did-not","errorCode":null,"errorMessage":"'cargo metadata' for the Rust app '{resourceName}' did not complete within {s_timeout.TotalSeconds:0} seconds.","messagePattern":"'cargo metadata' for the Rust app '(.+?)' did not complete within (.+?) seconds\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Rust/CargoMetadataReader.cs","lineNumber":111,"sourceCode":"                $\"Unable to start 'cargo' to inspect the Rust app '{resourceName}'. Install Rust from https://www.rust-lang.org/tools/install \" +\n                $\"or supply your own Dockerfile in '{workingDirectory}'. {ex.Message}\", ex);\n        }\n\n        // Drain both redirected streams concurrently so a full pipe cannot block cargo before it exits.\n        var stdoutTask = process.StandardOutput.ReadToEndAsync(CancellationToken.None);\n        var stderrTask = process.StandardError.ReadToEndAsync(CancellationToken.None);\n\n        using var timeoutSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);\n        timeoutSource.CancelAfter(s_timeout);\n\n        try\n        {\n            await process.WaitForExitAsync(timeoutSource.Token).ConfigureAwait(false);\n        }\n        catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested)\n        {\n            TryKillProcess(process);\n            throw new DistributedApplicationException(\n                $\"'cargo metadata' for the Rust app '{resourceName}' did not complete within {s_timeout.TotalSeconds:0} seconds.\");\n        }\n        catch (OperationCanceledException)\n        {\n            TryKillProcess(process);\n            throw;\n        }\n\n        var stdout = await stdoutTask.ConfigureAwait(false);\n        var stderr = await stderrTask.ConfigureAwait(false);\n\n        if (process.ExitCode != 0)\n        {\n            var diagnostic = FormatStandardError(stderr, environment, startInfo.Environment);\n            var diagnosticSuffix = diagnostic.Length > 0 ? $\" {diagnostic}\" : string.Empty;\n            throw new DistributedApplicationException(\n                $\"'cargo metadata' failed for the Rust app '{resourceName}' with exit code {process.ExitCode}.{diagnosticSuffix}\");\n        }","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Rust/CargoMetadataReader.cs#L93-L129","documentation":"ReadAsync waits for 'cargo metadata' with a fixed timeout (s_timeout). If the process does not exit in time — and the caller's own cancellation token was not the cause — the reader kills the cargo process and throws DistributedApplicationException reporting the timeout in seconds.","triggerScenarios":"'cargo metadata' run against a Rust workspace takes longer than s_timeout seconds: extremely large workspace, first-build index/download stalls, network-bound registry updates, or cargo hanging waiting for a package lock.","commonSituations":"Cold CI machines downloading the crate index/dependencies on first metadata call; enormous monorepo workspaces; cargo blocked on a file lock from another cargo process; offline environment where cargo stalls on network access; very slow disk.","solutions":["Warm the workspace first: run 'cargo metadata' or 'cargo fetch' once manually so subsequent calls are fast.","Check for competing cargo processes or stale lock files (~/.cargo/package cache lock, target dir lock) and remove them.","Reduce workspace size or point the resource at the specific crate directory instead of a huge monorepo root.","If offline, vendor dependencies or ensure a reachable crates.io mirror; retry the App Host run after the stall is cleared."],"exampleFix":"// shell — pre-warm cargo so apphost metadata call is fast\n// before\n$ aspire run   # cargo metadata times out on cold cache\n\n// after\n$ cargo fetch  # or: cargo metadata --format-version 1 > /dev/null\n$ aspire run","handlingStrategy":"retry","validationCode":"// Warm cargo caches before starting the apphost:\ncargo fetch || true","typeGuard":null,"tryCatchPattern":"try { /* start Rust resource */ }\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"did not complete within\"))\n{ /* check for cargo locks/network stalls, then retry once warmed */ }","preventionTips":["Pre-warm cargo (cargo fetch / one manual 'cargo metadata') on cold CI machines.","Avoid running concurrent cargo commands that contend on package-cache locks.","Keep Rust workspaces reasonably sized; point resources at the relevant crate directory.","Ensure reliable network access to crates.io or configure a mirror/vendor dependencies."],"tags":["rust","cargo","timeout","process"],"backgroundTag":"request-timeout","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}