windbg-user-mutex-held-across-co-await
Skill469 starsChanged 37 days agoMITView on GitHub
Use when app, service, or user-mode driver C++ coroutine code holds a thread-affine lock across suspension and later hangs or fails. Not for all coroutine crashes or choosing lock performance.
In this repository11 other files it gives its agents.
- windbg-diagnostic-methodSkill
- windbg-kernel-bugcheck-triageSkill
- windbg-kernel-irp-lifecycle-triageSkill
- windbg-kernel-lock-deadlock-triageSkill
- windbg-kernel-verifier-triageSkill
- windbg-user-exception-triageSkill
- windbg-user-heap-corruption-investigationSkill
- windbg-user-ttd-reverse-debugging-triageSkill
- windbg-user-virtual-memory-exhaustionSkill
- windbg-user-wait-chain-analysisSkill
- sample-skillSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 5 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 8
Load
windbg-diagnostic-methodfirst: if it is not already loaded in this conversation, and apply it throughout for evidence ranking, … - Very specific: line 30
Verify the awaiter's resumption contract.
- Distinctive: line 32
Do not assume every WinRT awaitable always resumes on a worker or always on the originating thread.
- Very specific: line 39
If the symptom is general blocking use windbg-user-wait-chain-analysis.
- Distinctive: line 58
Use RAII for each synchronous scope.
- Distinctive: line 63
Do not recommend a blanket mutex-type replacement.
- Distinctive: line 65
Keep the object and any captured interfaces alive across asynchronous work.
- Distinctive: line 69
No thread-affine lock ownership survives a suspension in the corrected path.
- Very specific: line 83
Follow FEEDBACK.md and report reviewed, sanitized feedback to WinDbg-Feedback.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Mutex Held Across co_await
Load windbg-diagnostic-method first if it is not already loaded in this
conversation, and apply it throughout for evidence ranking, hypothesis testing,
confidence calibration, independent review, and report validation. This skill
adds the bug-family-specific commands and evidence requirements.
Detection
This pattern can occur in native application, service, or user-mode driver
code, including UMDF components that use C++ coroutines. Look for a lock
acquired before co_await and released after resumption or
coroutine destruction. Mutex ownership belongs to the acquiring thread, not
the coroutine frame. A resumption on another thread can violate that contract.
Even same-thread resumption can create reentrancy or progress problems when
the awaited operation needs a lock the coroutine still holds.
Workflow
- Identify the exact lock primitive and acquisition/release scope in source. Audit every suspension point while the RAII guard or ownership is alive.
- Establish the acquire and resume threads using trace/source evidence. Standard mutexes and SRW locks do not provide a universally queryable owner field; do not fabricate an owning TID from undocumented layouts.
- Verify the awaiter's resumption contract. C++/WinRT can preserve apartment
context for particular awaitables;
resume_backgroundintentionally switches. Do not assume every WinRT awaitable always resumes on a worker or always on the originating thread. - Distinguish wrong-thread release, a dependency cycle, state changed during suspension, lifetime failure, and unrelated memory corruption.
- Move the thread-affine lock into synchronous scopes. Revalidate relevant state after the await rather than treating the pre-await snapshot as current.
If the symptom is general blocking use windbg-user-wait-chain-analysis. For damaged
heap objects use windbg-user-heap-corruption-investigation. If a recording is available,
windbg-user-ttd-reverse-debugging-triage can help establish the ownership timeline.
Fix pattern
Conceptual sequence, not a promise about any particular scheduler:
under lock:
take a snapshot and its generation
release lock
await work using that snapshot
under lock on the resumed thread:
revalidate generation, lifetime, and assumptions
apply result or explicitly handle a stale/cancelled operation
release lockUse RAII for each synchronous scope. If invariants cannot tolerate unlocking,
redesign the operation or use a specifically designed asynchronous coordination
primitive with cancellation/lifetime rules. Switching to a recursive mutex or
shared_mutex does not make a thread-affine lock coroutine-safe.
Do not recommend a blanket mutex-type replacement. Shared locking is a separate design decision; changing the primitive does not repair suspension ownership. Keep the object and any captured interfaces alive across asynchronous work.
Validation
- No thread-affine lock ownership survives a suspension in the corrected path.
- Each awaiter's thread/apartment contract is understood.
- State invariants are revalidated after suspension.
- Cancellation, concurrent mutation, shutdown, and failed awaited work are tested.
- The remedy removes the demonstrated cause, not just an observed exception.
References
- Holding a lock across coroutine suspension
- C++/WinRT concurrency and asynchronous operations
- Slim reader/writer locks
Feedback
Follow FEEDBACK.md and report reviewed, sanitized feedback to
WinDbg-Feedback.
Include windbg-user-mutex-held-across-co-await and the package version from plugin.json;
no automatic source, dump, or transcript upload.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

