{"record":{"id":"aea1b7d7ae7fa00a","repo":"denoland/deno","slug":"failed-to-spawn-desktop-runtime-thread","errorCode":null,"errorMessage":"failed to spawn desktop runtime thread","messagePattern":"failed to spawn desktop runtime thread","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"cli/rt_desktop/lib.rs","lineNumber":1451,"sourceCode":"\n/// Stack size for the thread the Deno runtime runs on. Laufey invokes\n/// `laufey_runtime_start` on its RuntimeLoader thread, which gets the\n/// platform-default stack for secondary threads — only 512KB on macOS.\n/// That is far too small for the runtime: synchronous module parsing (swc)\n/// alone recurses past it on real-world module graphs (e.g. a SvelteKit\n/// dev server's graph) and kills the process with SIGBUS. 8MB matches the\n/// headroom the CLI gets from the OS main thread.\nconst RUNTIME_THREAD_STACK_SIZE: usize = 8 * 1024 * 1024;\n\n/// Run `f` to completion on a dedicated thread with a stack large enough\n/// for the Deno runtime (see `RUNTIME_THREAD_STACK_SIZE`), keeping the\n/// calling (loader) thread parked until it finishes.\nfn run_on_runtime_thread<F: FnOnce() + Send + 'static>(f: F) {\n  let thread = std::thread::Builder::new()\n    .name(\"deno-desktop-runtime\".to_string())\n    .stack_size(RUNTIME_THREAD_STACK_SIZE)\n    .spawn(f)\n    .expect(\"failed to spawn desktop runtime thread\");\n  if thread.join().is_err() {\n    // The runtime thread panicked. The panic hook normally exits the\n    // process itself; this is a backstop in case it returned.\n    deno_runtime::exit(1);\n  }\n}\n\n/// Run as a headless worker (no Laufey window). Used when a framework dev\n/// server forks child processes that re-execute this dylib.\nfn run_headless_worker() {\n  denort::init_logging(None, None);\n  deno_runtime::deno_permissions::mark_standalone();\n  rustls::crypto::aws_lc_rs::default_provider()\n    .install_default()\n    .unwrap();\n\n  let rt = deno_runtime::tokio_util::create_basic_runtime();\n","sourceCodeStart":1433,"sourceCodeEnd":1469,"githubUrl":"https://github.com/denoland/deno/blob/f7822238cab635a3a19f99f493f675fa81a7f9d8/cli/rt_desktop/lib.rs#L1433-L1469","documentation":"The desktop runtime library (cli/rt_desktop) runs the entire Deno event loop on a dedicated thread with an 8 MiB stack, matching the stack headroom the OS gives the CLI main thread - smaller stacks overflow on deep module graphs. If the OS itself refuses to create that thread, .expect() panics with 'failed to spawn desktop runtime thread' and the process aborts.","triggerScenarios":"Starting an application that loads the desktop runtime dylib when thread/process creation fails: RLIMIT_NPROC (ulimit -u) or cgroup pids.max exhausted, insufficient memory to reserve the 8 MiB stack, or a sandbox that forbids thread creation.","commonSituations":"CI containers and orchestrators with low pids limits; framework dev servers that fork many child processes; heavily parallel test machines; memory-constrained devices or containers.","solutions":["Raise thread/process limits: ulimit -u, cgroup pids.max, systemd TasksMax","Reduce the number of concurrently spawned child processes and workers","Free memory or raise the container memory limit so the 8 MiB stack can be reserved","If it reproduces with plain `deno run`, file a deno issue with environment details"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# preflight before launching the desktop runtime\nulimit -u\nps -eLf | wc -l\ncat /sys/fs/cgroup/pids.max 2>/dev/null || cat /sys/fs/cgroup/pids/pids.max 2>/dev/null\n# if the process count is near the limit, raise the limit or reduce children first","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set adequate ulimit -u / cgroup pids.max / systemd TasksMax in deployment units","Bound the number of concurrent child processes and worker threads your app spawns","Monitor thread counts and memory so exhaustion is caught before the panic"],"tags":["thread","panic","resource-exhaustion","desktop-runtime","stack-size"],"backgroundTag":"thread-creation-failed","analyzedSha":"f7822238cab635a3a19f99f493f675fa81a7f9d8","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}