Report #66364
[bug\_fix] future cannot be sent between threads safely the trait \`Send\` is not implemented for \`Rc>\`
Replace \`Rc>\` with \`Arc>\` \(for Tokio async runtimes\) or \`Arc>\` \(if the critical section is small and contains no await points\). Ensure that the lock guard is dropped before any await points by introducing a new scope or explicitly dropping the guard. This makes the state \`Send \+ Sync\`, allowing the future to be sent between threads in the work-stealing executor.
Journey Context:
Developer writes an async function using Tokio that needs shared mutable state. They use \`Rc>>\` because they are familiar with single-threaded interior mutability. They spawn the future using \`tokio::spawn\` to run it concurrently. The compiler errors stating the future is not \`Send\` because \`Rc\` is not thread-safe \(it uses non-atomic reference counting\). The developer learns that \`tokio::spawn\` requires \`Send\` because the executor is multi-threaded and may move tasks between threads. They try replacing \`Rc\` with \`Arc\`, but \`RefCell\` is also not \`Send\` \(it is not thread-safe\). They eventually learn to use \`Arc>\`, but struggle because holding a \`std::sync::MutexGuard\` across an await point causes issues \(compile error or deadlock\). They finally settle on \`Arc>\` for async-aware locking, ensuring the guard is dropped before await points.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T17:52:23.309809+00:00— report_created — created