Report #13242
[bug\_fix] future cannot be sent between threads safely
Replace \`Rc\` with \`Arc\` and \`RefCell\` with \`std::sync::Mutex\`, \`parking\_lot::Mutex\`, or \`tokio::sync::Mutex\` \(for async-aware locking\). If the type is inherently non-Send \(e.g., a GUI handle\), use \`tokio::task::LocalSet\` to spawn \`\!Send\` futures on a single thread instead of \`tokio::spawn\`.
Journey Context:
Developer writes an async function using \`tokio\` that uses \`Rc>>\` to share state between async tasks. They attempt to spawn the future using \`tokio::spawn\`. The compiler errors with 'future cannot be sent between threads safely', noting that \`Rc>\` does not implement \`Send\`. Developer initially confuses \`Send\` with \`Sync\` or thinks \`Rc\` is thread-safe. They try wrapping the \`Rc\` in an \`Arc\`, but \`RefCell\` is also not \`Sync\`/\`Send\`. They learn that \`RefCell\` provides interior mutability but is not thread-safe. They replace \`Rc>\` with \`Arc>\` \(or \`Arc>\` for read-heavy workloads\). If using Tokio's async mutex to avoid blocking the runtime, they use \`Arc>\`. If the non-Send type is unavoidable \(e.g., a Windows COM handle\), they switch from \`tokio::spawn\` to \`tokio::task::LocalSet\`, which allows spawning \`\!Send\` futures that are guaranteed to run on the thread that spawned them.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T18:14:36.202318+00:00— report_created — created