tokio-rs/tokio · error · syn::Error

`worker_threads` set multiple times.

Error message

`worker_threads` set multiple times.

What it means

`set_worker_threads` (entry.rs:130) records the first `worker_threads = N` and rejects any second occurrence in the same attribute. `worker_threads` is meaningful only for the `multi_thread` flavor, but the duplicate check runs at parse time regardless.

Source

Thrown at tokio-macros/src/entry.rs:134

            return Err(syn::Error::new(span, "`flavor` set multiple times."));
        }

        let runtime_str = parse_string(runtime, span, "flavor")?;
        let runtime =
            RuntimeFlavor::from_str(&runtime_str).map_err(|err| syn::Error::new(span, err))?;
        self.flavor = Some(runtime);
        Ok(())
    }

    fn set_worker_threads(
        &mut self,
        worker_threads: syn::Lit,
        span: Span,
    ) -> Result<(), syn::Error> {
        if self.worker_threads.is_some() {
            return Err(syn::Error::new(
                span,
                "`worker_threads` set multiple times.",
            ));
        }

        let worker_threads = parse_int(worker_threads, span, "worker_threads")?;
        if worker_threads == 0 {
            return Err(syn::Error::new(span, "`worker_threads` may not be 0."));
        }
        self.worker_threads = Some((worker_threads, span));
        Ok(())
    }

    fn set_start_paused(&mut self, start_paused: syn::Lit, span: Span) -> Result<(), syn::Error> {
        if self.start_paused.is_some() {
            return Err(syn::Error::new(span, "`start_paused` set multiple times."));
        }

        let start_paused = parse_bool(start_paused, span, "start_paused")?;
        self.start_paused = Some((start_paused, span));

View on GitHub (pinned to 625954f365)

Solutions

  1. Remove the duplicate `worker_threads` so a single value remains.
  2. Pick one worker count and delete the other.

Example fix

// before
#[tokio::main(flavor = "multi_thread", worker_threads = 2, worker_threads = 4)]
async fn main() {}

// after
#[tokio::main(flavor = "multi_thread", worker_threads = 4)]
async fn main() {}
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Writing `#[tokio::main(worker_threads = 2, worker_threads = 4)]`.

Common situations: Conditionally-edited attributes where an old value was left in place; copy-paste.

Related errors


AI-assisted analysis of tokio-rs/tokio@625954f365 (2026-08-11). Data as JSON: /api/errors/7c4bb0ad70068f41. Report an issue: GitHub.