Report #4038
[bug\_fix] future cannot be sent between threads safely \(E0277\) in tokio::spawn
Replace non-Send types \(\`Rc\`, \`RefCell\`, raw pointers, or \`&T\` references to non-Sync data\) with thread-safe alternatives \(\`Arc\`, \`Mutex\`/\`RwLock\`, or \`Atomic\` types\), ensuring all data captured by the async block implements \`Send\`.
Journey Context:
Developer writes an async function using \`tokio::spawn\` to run background tasks concurrently. Inside the async block, they use \`Rc::new\(data\)\` for reference counting or \`RefCell\` for interior mutability, assuming it will work like synchronous code. The compiler gives a cryptic error about \`dyn Future\` not implementing \`Send\`, pointing to the \`Rc\` or \`RefCell\`. Developer learns that \`tokio::spawn\` requires \`Send\` futures because the task may move between threads in the work-stealing runtime. They refactor to use \`Arc\` and \`Mutex\` \(or \`tokio::sync::Mutex\` for async-aware locking\), satisfying the \`Send\` bound.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:42:26.271195+00:00— report_created — created