Report #40648
[bug\_fix] Future cannot be sent between threads safely: \`Rc>\` is not \`Send\`
Replace \`Rc\` with \`Arc\` \(atomic reference counting\) and \`RefCell\` with \`tokio::sync::Mutex\` \(or \`std::sync::Mutex\` if not held across await points\) to make the shared state thread-safe \(\`Send \+ Sync\`\) for the multi-threaded async runtime.
Journey Context:
A developer writes an async handler using \`tokio\` that shares state: \`let state = Rc::new\(RefCell::new\(HashMap::new\(\)\)\);\`. They clone the \`Rc\` and move it into an async block, then spawn it with \`tokio::spawn\`. The compiler errors: "future cannot be sent between threads safely: \`Rc>\` is not \`Send\`". The developer learns that \`tokio::spawn\` requires the future to be \`Send\` so it can move between threads in the work-stealing runtime. \`Rc\` and \`RefCell\` are single-threaded types \(\`\!Send\`\). The fix involves swapping \`Rc\` for \`Arc\` \(atomic\) and \`RefCell\` for a mutex. For async, \`tokio::sync::Mutex\` is preferred over \`std::sync::Mutex\` because the latter cannot be held across \`.await\` points without blocking the runtime.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T22:42:02.997176+00:00— report_created — created