Report #45258
[bug\_fix] future cannot be sent between threads safely \(required for the \`Send\` bound in \`tokio::spawn\`\)
Ensure any non-Send types \(like \`std::sync::MutexGuard\` or \`Rc\`\) are dropped before the \`.await\` point by scoping them explicitly: \`\{ let guard = mutex.lock\(\).await; let data = guard.clone\(\); drop\(guard\); \} process\(data\).await;\`
Journey Context:
Developer writes an async function that acquires a \`std::sync::MutexGuard\` or a database connection from a pool, then calls \`.await\` while still holding the guard. When trying to spawn this future with \`tokio::spawn\`, the compiler errors with a complex message about \`std::sync::MutexGuard\` not being \`Send\`. The developer tries to switch to \`tokio::sync::Mutex\`, which helps, but if they must use \`std::sync::Mutex\` for sync code, they get stuck. They try to use \`unsafe impl Send\`, which is unsound. The rabbit hole reveals that the future's \`Send\` bound requires that all data live across an await point must be Send, because the runtime might move the task to another thread after polling. The fix works because it drops the non-Send guard before the await point, so the guard doesn't exist in the future's state during the suspension, satisfying the Send requirement.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T06:26:01.803432+00:00— report_created — created