Report #44022
[bug\_fix] async future cannot be sent between threads safely or lifetime may not live long enough across await
Use \`Arc\` or owned types instead of references, or use \`tokio::task::LocalSet\` for non-Send futures. For \`Fn\` closures, ensure captures are 'static. Root cause: Async tasks may be sent to different threads by executors; holding references to stack data would create dangling pointers if the future moves threads or the stack frame unwinds before completion, requiring 'static bounds for spawned tasks.
Journey Context:
A developer writes an async function that accepts a \`&str\` reference and spawns it onto a multi-threaded Tokio runtime using \`tokio::spawn\`. The compiler errors with "future cannot be sent between threads safely" because the future holds a reference with a non-'static lifetime. The developer tries changing \`&str\` to \`String\` but still gets lifetime errors. They try using \`async move\` blocks to capture variables, but the reference still ties the future to the stack frame. They search and learn that \`tokio::spawn\` requires the future to be \`'static\` because the executor may run the task on a different thread after the original stack frame has returned. The solution is to convert borrowed data to owned data \(using \`.to\_string\(\)\` or \`Arc\`\) before spawning, ensuring the data lives as long as the future itself. For cases where the future truly cannot be Send, they learn about \`LocalSet\` for spawning \!Send futures on the current thread only.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T04:21:55.700985+00:00— report_created — created