{"record":{"id":"221e15bb8a965c8a","repo":"gleam-lang/gleam","slug":"unable-to-start-tokio-async-runtime","errorCode":null,"errorMessage":"Unable to start Tokio async runtime","messagePattern":"Unable to start Tokio async runtime","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-cli/src/hex.rs","lineNumber":39,"sourceCode":"    match credentials {\n        hexpm::Credentials::ApiKey(key) => Ok(hexpm::WriteActionCredentials::ApiKey(key.clone())),\n        hexpm::Credentials::OAuthAccessToken(token) => {\n            let one_time_password = cli::ask(\"Enter your two-factor authentication code\")?.into();\n            Ok(hexpm::WriteActionCredentials::OAuthAccessToken {\n                access_token: token.clone(),\n                one_time_password,\n            })\n        }\n    }\n}\n\npub fn retire(\n    package: String,\n    version: String,\n    reason: RetirementReason,\n    message: Option<String>,\n) -> Result<()> {\n    let runtime = tokio::runtime::Runtime::new().expect(\"Unable to start Tokio async runtime\");\n    let config = hexpm::Config::new();\n    let http = HttpClient::new();\n    let credentials =\n        HexAuthentication::new(&runtime, &http, config.clone()).get_or_create_api_credentials()?;\n\n    runtime.block_on(hex::retire_release(\n        &package,\n        &version,\n        reason,\n        message.as_deref(),\n        &write_credentials(&credentials)?,\n        &config,\n        &http,\n    ))?;\n    cli::print_retired(&package, &version);\n    Ok(())\n}\n","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-cli/src/hex.rs#L21-L57","documentation":"Panic from `tokio::runtime::Runtime::new().expect(\"Unable to start Tokio async runtime\")` in compiler-cli/src/hex.rs retire(). Tokio failed to create its async runtime, almost always because the process cannot spawn worker threads or install the reactor (resource exhaustion, or a runtime already being initialized in a context that forbids it). The CLI cannot perform any async Hex API call without it.","triggerScenarios":"Calling gleam's hex retire when Runtime::new() returns Err: thread spawn failure (ulimit -u exhausted, cgroup pids limit, low memory) or running inside an environment where tokio cannot initialize the I/O driver.","commonSituations":"Running the gleam CLI in restricted containers/CI with very low limits; embedding gleam inside another Rust binary that already owns a Tokio runtime and calls this sync function from a runtime thread in ways that exhaust resources.","solutions":["Check and raise process/thread limits (ulimit -u, container pids/memory limits) on the machine running the CLI.","Free memory or reduce system load; Runtime::new fails when the OS cannot allocate resources.","If embedding gleam, call retire from a non-async context or refactor to reuse an existing runtime instead of creating a new one.","Replace the expect with graceful error handling that prints guidance instead of panicking."],"exampleFix":"// before\nlet runtime = tokio::runtime::Runtime::new().expect(\"Unable to start Tokio async runtime\");\n// after\nlet runtime = tokio::runtime::Runtime::new()\n    .map_err(|e| anyhow::anyhow!(\"Unable to start Tokio async runtime: {e}\"))?;","handlingStrategy":"fallback","validationCode":"// Check resources before running the CLI:\n// ulimit -u; cat /sys/fs/cgroup/pids.max; free -m","typeGuard":null,"tryCatchPattern":"// std::panic::catch_unwind around the sync hex call when embedding:\nlet result = std::panic::catch_unwind(|| gleam_hex::retire(pkg, ver, reason, msg));","preventionTips":["Run CLI commands with adequate thread/memory limits.","Avoid calling sync hex functions from inside another Tokio runtime.","Surface runtime-creation errors as Result instead of expect in library code."],"tags":["rust","tokio","runtime","panic"],"backgroundTag":"module-init-failed","analyzedSha":"15b07c783065c92bb016b1b74ed0995a5259850f","analyzedAt":"2026-09-14T11:14:59.388Z","contentChangedAt":"2026-09-14T11:14:59.388Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}