{"record":{"id":"1ce012f4da3ed9bc","repo":"gitbutlerapp/gitbutler","slug":"failed-to-create-tokio-runtime-err","errorCode":null,"errorMessage":"Failed to create tokio runtime: {err}","messagePattern":"Failed to create tokio runtime: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-forge/src/ci.rs","lineNumber":145,"sourceCode":"                        })\n                        .collect()\n                })\n            })\n        }\n        ForgeName::GitLab => {\n            let preferred_account = preferred_forge_user\n                .as_ref()\n                .and_then(|user| user.gitlab().cloned());\n\n            // Clone owned data for thread\n            let project_id = but_gitlab::GitLabProjectId::new(owner, repo);\n            let storage = storage.clone();\n            let reference = reference.to_string();\n            let reference_for_checks = reference.clone();\n\n            let pipelines = std::thread::spawn(move || -> anyhow::Result<_> {\n                let runtime = tokio::runtime::Runtime::new()\n                    .map_err(|err| anyhow::anyhow!(\"Failed to create tokio runtime: {err}\"))?;\n                runtime.block_on(but_gitlab::checks::list_pipeline_jobs_for_ref(\n                    preferred_account.as_ref(),\n                    project_id,\n                    &reference,\n                    &storage,\n                ))\n            })\n            .join()\n            .map_err(|e| anyhow::anyhow!(\"Failed to join thread: {e:?}\"))??;\n            Ok(Some(\n                pipelines\n                    .into_iter()\n                    .map(|pipeline| {\n                        let mut ci_check = CiCheck::from(pipeline);\n                        ci_check.reference = reference_for_checks.to_string();\n                        ci_check\n                    })\n                    .collect(),","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-forge/src/ci.rs#L127-L163","documentation":"ci_checks_for_ref spawns a dedicated std::thread to run async GitLab CI queries, and inside that thread creates a fresh tokio Runtime. If tokio cannot build a runtime (typically an invalid/feature-limited build, exhausted resources, or a runtime-incompatible environment) this anyhow error is returned. It surfaces before any GitLab API call is attempted.","triggerScenarios":"Calling ci_checks_for_ref (via fetch_and_refresh_cache) for a GitLab reference when tokio::runtime::Runtime::new() fails — e.g. binary built without needed tokio features, extreme resource limits (thread/memory exhaustion), or incompatible runtime environment.","commonSituations":"Restricted containers with low thread limits; misbuilt binaries (tokio features disabled); heavily loaded CI machines where thread creation fails.","solutions":["Rebuild with tokio enabled with required features (rt-multi-thread, macros): check Cargo feature flags","Check system thread/memory limits (ulimit -u, cgroup limits) and raise them","Refactor to use an existing shared tokio runtime or a runtime handle instead of constructing a new Runtime per thread"],"exampleFix":"// before\nlet runtime = tokio::runtime::Runtime::new()\n    .map_err(|err| anyhow::anyhow!(\"Failed to create tokio runtime: {err}\"))?;\n// after\nlet runtime = HANDLE.get_or_try_init(tokio::runtime::Runtime::new)?; // shared lazily-created runtime","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match fetch_and_refresh_cache(...).await {\n    Err(e) if e.to_string().contains(\"Failed to create tokio runtime\") => {\n        eprintln!(\"tokio runtime unavailable: {e:#}\");\n        Err(e)\n    }\n    other => other,\n}","preventionTips":["Build with tokio rt-multi-thread features enabled","Avoid restrictive thread/memory limits in containers running but","Use a single shared runtime rather than constructing one per thread"],"tags":["tokio","async-runtime","gitlab","ci"],"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"}