Report #7628
[bug\_fix] future cannot be sent between threads safely the trait \`Send\` is not implemented for \`Rc>\` \(E0277\)
Replace \`Rc\` with \`Arc\` and \`RefCell\` with \`Mutex\` or \`RwLock\` \(e.g., \`Arc>\`\). If the data is truly thread-local and must stay on one thread, use \`tokio::task::LocalSet\` instead of \`tokio::spawn\`. This works because \`tokio::spawn\` requires the future to be \`Send\` so the work-stealing runtime can move it between threads for load balancing; \`Rc\` and \`RefCell\` are not \`Send\` because they lack atomic reference counting and thread-safety checks.
Journey Context:
Developer is writing a high-performance async TCP server using Tokio. They need shared mutable state for a connection counter. They use \`let counter = Rc::new\(RefCell::new\(0\)\);\` and clone it into an \`async move\` block that they spawn with \`tokio::spawn\`. The compiler immediately stops with a complex error: \`future cannot be sent between threads safely\`. The error points to \`Rc>\` not implementing \`Send\`. The developer initially tries to remove the \`move\` keyword or use \`Arc\` instead of \`Rc\`, but \`RefCell\` is also not \`Send\`. Realizing that \`tokio::spawn\` may execute the future on a different thread than where it was created, they understand that \`Rc\` \(non-atomic\) and \`RefCell\` \(no thread locks\) are fundamentally unsafe to send across thread boundaries. After consulting the Tokio documentation on 'Spawning' and 'Sharing State', they refactor to use \`Arc>\`, which implements \`Send \+ Sync\`, satisfying the requirements of \`tokio::spawn\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T03:17:53.724312+00:00— report_created — created