Report #14285
[bug\_fix] future cannot be sent between threads safely the trait bound \`std::sync::MutexGuard<'\_, T>: Send\` is not satisfied
Replace \`std::sync::Mutex\` with \`tokio::sync::Mutex\` \(which is designed to be held across await points\), or restructure the code to drop the \`MutexGuard\` before any \`await\`. Root cause: \`std::sync::MutexGuard\` is not \`Send\` on all platforms \(it uses pthreads\), so holding it across an await point violates the \`Send\` requirement of spawned async tasks in work-stealing executors.
Journey Context:
Developer writes an async function that uses a shared counter wrapped in \`std::sync::Arc>\`. They lock the mutex, then perform an async I/O operation \(like \`tokio::time::sleep\`\) while holding the guard, then unlock implicitly. The compiler throws a cryptic error about \`Send\` not being implemented for \`MutexGuard\`. The developer first tries adding \`Send\` bounds to their type parameters, which doesn't help. They then realize the issue is the guard itself. After searching, they discover that Tokio provides an async-aware \`Mutex\` that yields the lock across await points safely, or they refactor to release the lock before the await.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:12:47.593269+00:00— report_created — created