{"record":{"id":"37e9925f14eee54a","repo":"gleam-lang/gleam","slug":"unable-to-start-tokio-async-runtime-37e992","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/owner.rs","lineNumber":12,"sourceCode":"// SPDX-License-Identifier: Apache-2.0\n// SPDX-FileCopyrightText: 2025 The Gleam contributors\n\nuse crate::{cli, http::HttpClient};\nuse gleam_core::{Result, hex};\n\npub fn add(\n    package: String,\n    new_owner_username_or_email: String,\n    level: hexpm::OwnerLevel,\n) -> Result<()> {\n    let runtime = tokio::runtime::Runtime::new().expect(\"Unable to start Tokio async runtime\");\n    let http = HttpClient::new();\n    let hex_config = hexpm::Config::new();\n    let credentials = crate::hex::HexAuthentication::new(&runtime, &http, hex_config.clone())\n        .get_or_create_api_credentials()?;\n\n    cli::print_adding_owner();\n    runtime.block_on(hex::add_owner(\n        &crate::hex::write_credentials(&credentials)?,\n        package,\n        new_owner_username_or_email,\n        level,\n        &hex_config,\n        &http,\n    ))?;\n    cli::print_added_owner();\n\n    Ok(())\n}","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/gleam-lang/gleam/blob/7e623aa83da3776faee50ca4ab9a6c40124acd95/compiler-cli/src/owner.rs#L1-L30","documentation":"`gleam add <pkg>` (owner.rs::add) creates a multi-thread Tokio runtime to drive reqwest HTTP calls against hex.pm, and Runtime::new() must succeed (expect(\"Unable to start Tokio async runtime\")). Runtime creation fails when the process cannot allocate the runtime's worker threads or set up its I/O driver — i.e. resource exhaustion (thread/memory limits), not anything about the package being added. The panic occurs before any network request, so credentials are never even read.","triggerScenarios":"Running `gleam add` inside a container with a tiny pids limit (docker --pids-limit), under a low `ulimit -u`/`ulimit -v`, in a cgroup near its memory ceiling so thread stacks can't be mapped, or in a seccomp sandbox that blocks epoll/clone for the I/O driver.","commonSituations":"Docker/Devcontainer/Podman defaults (pids-limit=10..100), shared CI runners during heavy parallel builds, gVisor/Firecracker microVMs with restricted syscalls, systems at their global thread limit from other tooling.","solutions":["Raise the process/thread limits and retry: `ulimit -u 4096` (or raise nproc limits in limits.conf), and in docker use `--pids-limit 256` or remove it.","Free memory pressure (stop parallel builds, add swap) so the runtime's worker stacks can be allocated, then retry the command.","If you embed this code path, build a cheaper runtime instead: tokio::runtime::Builder::new_current_thread().enable_all().build() still satisfies reqwest here.","Check `dmesg`/container events for OOM or cgroup pids-max denials to confirm the resource that ran out."],"exampleFix":"# before: container with a very low pids limit\ndocker run --pids-limit 16 my-gleam-ci gleam add gleam_http\n# panics: Unable to start Tokio async runtime\n\n# after: enough headroom for worker threads\ndocker run --pids-limit 512 my-gleam-ci gleam add gleam_http","handlingStrategy":"retry","validationCode":"# Check thread headroom before running gleam add in CI\nulimit -u          # soft nproc limit; raise if tiny (e.g. < 512)\ncat /sys/fs/cgroup/pids/current 2>/dev/null   # container usage vs pids.max\n# if too low, raise limits first, then run:\nulimit -u 4096 2>/dev/null; gleam add gleam_http","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give CI containers generous pids limits (docker --pids-limit 512+) when the job runs gleam/other Tokio tools.","Avoid running gleam add concurrently with heavy parallel builds that consume the thread budget.","Script the command to retry once after freeing resources, since nothing is mutated before the runtime starts."],"tags":["panic","tokio","runtime","threads","resource-limits","container","gleam-add"],"backgroundTag":"thread-creation-failed","analyzedSha":"7e623aa83da3776faee50ca4ab9a6c40124acd95","analyzedAt":"2026-08-17T00:07:02.091Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}