Report #88858
[bug\_fix] future cannot be sent between threads safely / cannot return value referencing local variable \(in async\)
Ensure the async block or future owns its data by changing references to owned types \(e.g., \`String\` instead of \`&str\`\) or by using \`Arc\` to share ownership, satisfying the \`'static\` requirement for spawned tasks.
Journey Context:
A developer writes an async function \`async fn fetch\_data\(key: &str\) -> String\`. They call it in a Tokio application and try to spawn it onto the runtime with \`tokio::spawn\(fetch\_data\(&local\_string\)\)\`. The compiler errors with a complex message about the future not being \`Send\` or not living long enough. The developer tries to add \`\+ 'static\` bounds to the function, which doesn't help because the issue is the captured reference. They read the async book and realize that \`tokio::spawn\` requires the future to be \`'static\` because the task may run on a different thread after the calling function's stack frame is gone. The fix is to change the function signature to take \`String\` instead of \`&str\`, ensuring the future owns its data. The developer also learns to use \`Arc\` for sharing data between tasks when necessary.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T07:44:17.817159+00:00— report_created — created