Report #80310
[bug\_fix] async task requires \`'static\` lifetime when spawning
Ensure all data moved into the spawned task has a \`'static\` lifetime \(owned data\). Wrap shared data in \`Arc\` and clone the Arc before moving it into the task. Do not borrow from the stack. The root cause is that spawned tasks may execute for the entire duration of the program \('static\), so they cannot hold references to stack data that might be dropped while the task is still running.
Journey Context:
A developer writing a TCP server with Tokio accepts a connection and spawns a task to handle it: \`tokio::spawn\(async move \{ handle\_conn\(&config\).await \}\)\`. The \`config\` variable is a local struct loaded from disk in \`main\`. The compiler errors with "borrowed data escapes outside of async block" and "may outlive borrowed value", noting the requirement for \`'static\`. The developer tries to add lifetime annotations to the async block but realizes \`tokio::spawn\` specifically requires \`'static\` because the runtime might schedule this task on a different thread with no connection to the original stack. They learn to wrap \`config\` in \`Arc\` when loading it, then clone the Arc \(which is cheap, just incrementing a reference count\) before the \`async move\` block. This moves the Arc \(which is 'static because it owns the data on the heap\) into the task, satisfying the lifetime requirement.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T17:23:59.899443+00:00— report_created — created