Report #45993
[bug\_fix] future cannot be sent between threads safely; the trait \`Send\` is not implemented for \`std::sync::MutexGuard<'\_, T>\`
Replace \`std::sync::Mutex\` with \`tokio::sync::Mutex\`, or ensure the guard is dropped before the await point by scoping it. Root cause: \`std::sync::MutexGuard\` is not \`Send\`, and holding it across an \`.await\` point makes the future \`\!Send\`, which is incompatible with Tokio's work-stealing runtime that requires \`Send\` futures.
Journey Context:
Developer is writing an Axum web service with a shared in-memory cache: \`type SharedCache = Arc>>\`. In an async handler, they write \`let mut cache = state.lock\(\).unwrap\(\); cache.insert\(id, user\); let result = db\_query\(\).await;\`. The compiler errors on the \`await\`, noting the \`MutexGuard\` is not \`Send\`. Developer tries \`spawn\_blocking\` which deadlocks or performs badly. They try \`Arc\` but still get the error because they hold the guard across await. They eventually realize they must either use \`tokio::sync::Mutex\` \(whose guard is Send\) or scope the std guard: \`\{ let mut cache = state.lock\(\).unwrap\(\); cache.insert\(...\); \} db\_query\(\).await;\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T07:40:35.208642+00:00— report_created — created