{"record":{"id":"4011e9d62523cdb6","repo":"leptos-rs/leptos","slug":"could-not-create-futures-executor-threadpool","errorCode":null,"errorMessage":"could not create futures executor ThreadPool","messagePattern":"could not create futures executor ThreadPool","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"any_spawner/src/lib.rs","lineNumber":266,"sourceCode":"    pub fn init_futures_executor() -> Result<(), ExecutorError> {\n        use futures::{\n            executor::{LocalPool, LocalSpawner, ThreadPool},\n            task::{LocalSpawnExt, SpawnExt},\n        };\n        use std::cell::RefCell;\n\n        // Keep the lazy-init ThreadPool and thread-local LocalPool for spawn_local impl\n        static THREAD_POOL: OnceLock<ThreadPool> = OnceLock::new();\n        thread_local! {\n            static LOCAL_POOL: RefCell<LocalPool> = RefCell::new(LocalPool::new());\n            // SPAWNER is derived from LOCAL_POOL, keep it for efficiency inside the closure\n            static SPAWNER: LocalSpawner = LOCAL_POOL.with(|pool| pool.borrow().spawner());\n        }\n\n        fn get_thread_pool() -> &'static ThreadPool {\n            THREAD_POOL.get_or_init(|| {\n                ThreadPool::new()\n                    .expect(\"could not create futures executor ThreadPool\")\n            })\n        }\n\n        let executor_impl = ExecutorFns {\n            spawn: |fut| {\n                get_thread_pool()\n                    .spawn(fut)\n                    .expect(\"failed to spawn future on ThreadPool\");\n            },\n            spawn_local: |fut| {\n                // Use the thread_local SPAWNER derived from LOCAL_POOL\n                SPAWNER.with(|spawner| {\n                    spawner\n                        .spawn_local(fut)\n                        .expect(\"failed to spawn local future\");\n                });\n            },\n            poll_local: || {","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/any_spawner/src/lib.rs#L248-L284","documentation":"This panic comes from lazily initializing the global futures-executor ThreadPool inside `init_futures_executor` (any_spawner). `futures::executor::ThreadPool::new()` returns a Result and fails only when the underlying thread pool builder cannot spawn any worker threads (typically when `ThreadPoolBuilder::build()` hits an OS-level thread creation failure). any_spawner wraps this in `.expect`, so pool creation failure aborts the process on the first spawned task.","triggerScenarios":"Calling `any_spawner::_executor::init_futures_executor()` (directly or via Leptos' platform bootstrap) and then spawning the first future, on a system where thread creation fails: thread/process rlimit exhausted (RLIMIT_NPROC), memory exhaustion, restricted container/seccomp sandbox forbidding clone/pthread_create, or a heavily cgroup-limited environment.","commonSituations":"Running in minimal Docker containers or Kubernetes pods with low pids limits (e.g. pids.max), serverless/WASM-adjacent or CI sandboxes that disallow spawning threads, machines that have hit `ulimit -u`, or memory-starved hosts where the futures ThreadPool builder cannot allocate its threads.","solutions":["Raise the thread/process limit (ulimit -u, container pids cgroup) and free memory, then restart the application","Ensure exactly one executor init and that another executor (tokio, async-executor, glib) is available; call `init_tokio`/`init_async_executor` instead of `init_futures_executor` on thread-restricted platforms","Wrap pool creation context: run the app in an environment where `std::thread::Builder::new().spawn()` succeeds (verify with a small probe before bootstrapping)","Pin/upgrade any_spawner and futures-executor versions so ThreadPoolBuilder configuration matches your runtime"],"exampleFix":"// before\nany_spawner::executor::init_futures_executor().expect(\"init executor\");\n// after\n#[cfg(feature = \"tokio\")]\nany_spawner::executor::init_tokio().expect(\"init tokio executor\");\n#[cfg(not(feature = \"tokio\"))]\nany_spawner::executor::init_futures_executor().expect(\"init futures executor\");","handlingStrategy":"validation","validationCode":"fn can_spawn_thread() -> bool {\n    std::thread::Builder::new()\n        .name(\"probe\".into())\n        .spawn(|| {})\n        .map(|h| { let _ = h.join(); true })\n        .unwrap_or(false)\n}\nassert!(can_spawn_thread(), \"thread creation unavailable; raise ulimit/pids limit or use another executor\");","typeGuard":null,"tryCatchPattern":"// init itself returns Result; only pool creation inside panics\nif let Err(any_spawner::ExecutorError::AlreadySet) = any_spawner::executor::init_futures_executor() {\n    // already initialized elsewhere: fine\n}\n// guard the environment first (validationCode) since failure here panics","preventionTips":["Probe thread-creation ability at startup before choosing the futures executor","Raise ulimit -u / container pids limits for thread-hungry deployments","Prefer runtime-backed executors (tokio, async-executor) in containers and serverless","Initialize the executor exactly once, early, in a controlled environment"],"tags":["rust","thread-pool","executor-init","resource-exhaustion"],"backgroundTag":"thread-spawn-failed","analyzedSha":"32d20f6c9d517451d77beb68d88c7716823dac41","analyzedAt":"2026-09-01T18:55:42.580Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}