Report #9249
[bug\_fix] future cannot be sent between threads safely ... the trait \`Send\` is not implemented for \`std::rc::Rc>\`
Replace \`Rc>\` with \`Arc>\` \(or \`std::sync::Mutex\` if contention is low and holding across await is not needed\). If the data doesn't need to be mutated, use \`Arc\` alone. If the data is thread-local, ensure it is not held across await points by spawning the task locally.
Journey Context:
Developer writes an async function using Tokio and uses \`Rc::new\(RefCell::new\(data\)\)\` to share mutable state within a single task. When they try to spawn this future using \`tokio::spawn\`, the compiler errors with "future cannot be sent between threads safely" and specifically points out that \`Rc>\` is not \`Send\`. Developer initially tries to wrap the Rc in a struct and implement Send manually, which is unsafe and incorrect. They then learn that \`tokio::spawn\` requires the future to be Send because the Tokio runtime may move tasks between worker threads. The solution is to replace \`Rc\` \(single-threaded reference counting\) with \`Arc\` \(atomic reference counting\) and replace \`RefCell\` \(single-threaded interior mutability\) with a mutex. Since it's async, they should use \`tokio::sync::Mutex\` if they need to hold the lock across await points, or \`std::sync::Mutex\` if the critical section is small and non-blocking. After making these changes, the future becomes Send and the code compiles.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T07:42:53.614550+00:00— report_created — created