zed-industries/zed · error

failed to spawn threaded dispatcher worker

Error message

failed to spawn threaded dispatcher worker

What it means

ThreadedDispatcher::new spawns one worker thread per available parallelism; if thread::Builder::spawn returns Err (OS refused thread creation — resource limits, thread count exhausted), the unwrap panics because the dispatcher cannot function without its worker pool.

Source

Thrown at crates/gpui/src/platform/threaded_dispatcher.rs:147

        let thread_count =
            thread::available_parallelism().map_or(MIN_THREADS, |i| i.get().max(MIN_THREADS));
        for i in 0..thread_count {
            let mut receiver: PriorityQueueReceiver<RunnableVariant> = background_receiver.clone();
            let idle = idle.clone();
            thread::Builder::new()
                .name(format!("ThreadedDispatcherWorker-{i}"))
                .spawn(move || {
                    while let Ok(runnable) = receiver.pop() {
                        let _decrement = idle.decrement_on_drop();
                        let location = runnable.metadata().location;
                        let spawned = runnable.metadata().spawned;
                        profiler::update_running_task(spawned, location);
                        runnable.run();
                        profiler::save_task_timing();
                    }
                })
                .expect("failed to spawn threaded dispatcher worker");
        }
        drop(background_receiver);

        let timers = Arc::new(TimerQueue {
            state: Mutex::new(TimerQueueState {
                heap: BinaryHeap::new(),
                next_seq: 0,
            }),
            condvar: Condvar::new(),
        });
        {
            let timers = timers.clone();
            let idle = idle.clone();
            thread::Builder::new()
                .name("ThreadedDispatcherTimer".to_owned())
                .spawn(move || {
                    let mut state = timers.state.lock();
                    loop {

View on GitHub (pinned to 9d272b0363)

Solutions

  1. Check ulimit -u / cgroup thread limits (RLIMIT_NPROC, TasksMax) and raise them
  2. Free system resources or reduce concurrent thread consumption at startup
  3. Consider degrading to fewer worker threads instead of failing hard
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at crates/gpui/src/platform/threaded_dispatcher.rs:147 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-08-20). Data as JSON: /api/errors/fa7662b9df6fce20. Report an issue: GitHub.