{"record":{"id":"497c567f86c7c61d","repo":"gitbutlerapp/gitbutler","slug":"failed-fetch-review-review-number-failed-to-create-tokio","errorCode":null,"errorMessage":"Failed fetch review {review_number}: failed to create Tokio runtime: {e}","messagePattern":"Failed fetch review (.+?): failed to create Tokio runtime: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-forge/src/review.rs","lineNumber":2335,"sourceCode":"}\n\n/// Get a specific review (e.g. pull request) for a given forge repository\n///\n/// The resulting review will be cached.\npub fn get_forge_review(\n    preferred_forge_user: &Option<crate::ForgeUser>,\n    forge_repo_info: &crate::forge::ForgeRepoInfo,\n    review_number: usize,\n    db: &mut but_db::DbHandle,\n    storage: &but_forge_storage::Controller,\n) -> Result<ForgeReview> {\n    let preferred_forge_user = preferred_forge_user.clone();\n    let forge_repo_info = forge_repo_info.clone();\n    let storage = storage.clone();\n\n    let review = std::thread::spawn(move || {\n        let runtime = tokio::runtime::Runtime::new().map_err(|e| {\n            anyhow::anyhow!(\n                \"Failed fetch review {review_number}: failed to create Tokio runtime: {e}\"\n            )\n        })?;\n\n        runtime.block_on(get_forge_review_inner(\n            &preferred_forge_user,\n            &forge_repo_info,\n            review_number,\n            &storage,\n        ))\n    })\n    .join()\n    .map_err(|e| {\n        anyhow::anyhow!(\"Failed to fetch review {review_number}: thread panicked: {e:?}\")\n    })??;\n\n    // Cache the review and ignore any issues, if any.\n    crate::db::upsert_review(db, &review).ok();","sourceCodeStart":2317,"sourceCodeEnd":2353,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-forge/src/review.rs#L2317-L2353","documentation":"This error wraps the failure of `tokio::runtime::Runtime::new()` when `get_forge_review` spawns a dedicated OS thread to run an async forge-review fetch via `block_on`. Tokio runtime creation can only fail in restricted environments (e.g. resource limits preventing thread or socket-pool creation), and this message surfaces that low-level cause with the review number attached. It means the review fetch never even started because no async executor could be built.","triggerScenarios":"Calling `get_forge_review` on a system where `Runtime::new()` fails: the process has exhausted the ability to spawn threads (RLIMIT_NPROC / ulimit -u hit), insufficient memory for the runtime's blocking pool, or running inside a sandbox/container with restricted thread creation.","commonSituations":"CI containers with low thread limits; heavily loaded machines at the process/thread limit; memory-constrained environments; embedding the library in a process that already spawns many threads per operation.","solutions":["Check and raise the OS thread limit (ulimit -u / container pids limit) on the machine running the tool.","Free memory or increase the memory available to the process/container.","Retry the operation once resources are freed; the failure is environmental, not caused by the review number.","If embedding, avoid calling from an environment with per-thread restrictions or reduce concurrent fetch operations."],"exampleFix":"// before\nlet runtime = tokio::runtime::Runtime::new().map_err(|e| {\n    anyhow::anyhow!(\"Failed fetch review {review_number}: failed to create Tokio runtime: {e}\")\n})?;\n\n// after: verify thread limits first, e.g. on Linux\n// ulimit -u 4096   (raise the user process/thread limit)\n// or in a container: --pids-limit=4096\nlet runtime = tokio::runtime::Runtime::new().map_err(|e| {\n    anyhow::anyhow!(\"Failed fetch review {review_number}: failed to create Tokio runtime: {e}\")\n})?;","handlingStrategy":"try-catch","validationCode":"// Rust: rough resource pre-check before spawning\nlet ok = std::thread::available_parallelism().is_ok();\nif !ok { eprintln!(\"thread limits may block runtime creation\"); }","typeGuard":null,"tryCatchPattern":"match get_forge_review(...) {\n    Ok(review) => use(review),\n    Err(e) if e.to_string().contains(\"failed to create Tokio runtime\") => {\n        // environmental failure: raise thread limits / free memory, then retry once\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Keep OS thread limits (ulimit -u, container pids-limit) comfortably above expected concurrency","Avoid spawning one thread per fetch in embedded contexts; reuse a shared runtime","Monitor memory headroom on CI runners"],"tags":["tokio","runtime","resource-limit","forge"],"backgroundTag":"module-init-failed","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}