Report #4367
[bug\_fix] future cannot be sent between threads safely \(the trait \`Send\` is not implemented for \`Rc>\`\)
Replace \`Rc\` with \`Arc\` and \`RefCell\` with \`Mutex\` or \`RwLock\` \(e.g., \`Arc>\`\), ensuring the type implements \`Send \+ Sync\`. Alternatively, constrain the non-Send type to a scope that does not cross an \`.await\` point, or use \`spawn\_local\` \(e.g., in \`tokio::task::local\_set\`\) if the task must remain on a single thread. Root cause: \`tokio::spawn\` \(and similar\) requires the future to be \`Send\` so it can be moved between thread pool workers; \`Rc\` and \`RefCell\` are not thread-safe \(\`\!Send\`\).
Journey Context:
Developer writes an async web server using \`tokio\` and \`axum\`. They use \`Rc>\` to share mutable state within a single request handler, planning to clone the \`Rc\` for cheap shared ownership. When they try to spawn the handler with \`tokio::spawn\` or when the framework tries to run the future on the thread pool, they get a wall of errors about \`Rc>\` not being \`Send\`. They try wrapping in \`Mutex\` but keep the \`Rc\`, which still fails. They learn that \`Rc\` is not thread-safe and cannot be sent across threads even if never accessed concurrently. The fix is replacing \`Rc\` with \`Arc\` and \`RefCell\` with \`tokio::sync::RwLock\` or \`std::sync::Mutex\`, or using \`spawn\_local\` to keep the task on a single thread.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:18:06.506612+00:00— report_created — created