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

`flavor` set multiple times.

Error message

`flavor` set multiple times.

What it means

The `flavor = "..."` option selects the runtime flavor (`current_thread`, `local`, `multi_thread`). `set_flavor` (entry.rs:114) stores the first and rejects any second `flavor` key in the same attribute with a `syn::Error`.

Source

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

            is_test,
            crate_name: None,
            unhandled_panic: None,
        }
    }

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

        let runtime_name = parse_string(name, span, "name")?;
        self.name = Some(runtime_name);
        Ok(())
    }

    fn set_flavor(&mut self, runtime: syn::Lit, span: Span) -> Result<(), syn::Error> {
        if self.flavor.is_some() {
            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.",

View on GitHub (pinned to 625954f365)

Solutions

  1. Keep only one `flavor` argument.
  2. Decide on the single flavor the entry point needs and delete the rest.

Example fix

// before
#[tokio::main(flavor = "current_thread", flavor = "multi_thread", 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(flavor = "current_thread", flavor = "multi_thread")]`.

Common situations: Copy-paste; switching flavor and forgetting to delete the old one; macros that compose options.

Related errors


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