Report #13074
[bug\_fix] E0277: the trait bound \`std::sync::MutexGuard<'\_, T>: Send\` is not satisfied
Drop the \`std::sync::MutexGuard\` before the \`.await\` point by scoping it in a block \(\`\{ let guard = ...; ... \}\`\), or replace \`std::sync::Mutex\` with \`tokio::sync::Mutex\` \(whose guard is \`Send\`\) to hold the lock across await points.
Journey Context:
Developer writes an async function using Tokio. They acquire a standard library lock: \`let guard = self.mutex.lock\(\).unwrap\(\);\`. Immediately after, they call an async I/O operation like \`self.stream.write\_all\(&guard\).await\`. The compiler emits E0277 stating that the future cannot be sent between threads because \`std::sync::MutexGuard\` is not \`Send\` \(it cannot be safely moved to another OS thread\). The developer realizes that when the async function yields at the \`.await\` point, the current thread might switch to another task, or the task might be moved to a different thread in Tokio's work-stealing runtime. If the task is moved while holding a non-\`Send\` guard, the mutex guard \(which is thread-local\) would be corrupted. The fix is to ensure the guard is dropped before the await. The developer wraps the lock usage in a nested block: \`\{ let guard = self.mutex.lock\(\).unwrap\(\); /\* process data \*/ \}\` so the guard is dropped at the end of the block, before the \`await\`. Alternatively, if the lock must be held across the await, they switch to \`tokio::sync::Mutex\`, which is designed for async contexts and has a \`Send\` guard.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T17:43:27.707639+00:00— report_created — created