AGENT SKILL

WinDbg 协程互斥锁挂起排查

windbg-user-mutex-held-across-co-await

当应用、服务或用户态驱动的 C++ 协程代码在挂起点持有线程关联锁,随后发生挂起或失败时使用。不适用于所有协程崩溃场景,也不用于锁的性能选型。

License 许可
MIT
最近更新
2026-11-09
Stars
★ 510
Forks
41

01 前言 Front Matter

name
windbg-user-mutex-held-across-co-await
description
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.

03 SKILL.md 正文

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

  1. Identify the exact lock primitive and acquisition/release scope in source. Audit every suspension point while the RAII guard or ownership is alive.
  2. 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.
  3. Verify the awaiter's resumption contract. C++/WinRT can preserve apartment context for particular awaitables; resume_background intentionally switches. Do not assume every WinRT awaitable always resumes on a worker or always on the originating thread.
  4. Distinguish wrong-thread release, a dependency cycle, state changed during suspension, lifetime failure, and unrelated memory corruption.
  5. 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 lock

Use 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

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.

04 同仓库更多 Skills

microsoft
microsoft/win-dev-skills

技能目录测试示例

sample-skill

用于测试目录工具的示例技能。在测试 CI 时使用。不用于实际工作。

软件开发工程师示例与演示技能
★ 510
microsoft
microsoft/win-dev-skills

WinDbg 等待链阻塞分析

windbg-user-wait-chain-analysis

当应用、服务或用户态驱动宿主程序因锁、COM/RPC、I/O 或其他进程而无响应时,用于追踪阻塞链。不适用于仅由异常栈导致的崩溃。

软件开发工程师调试与故障排查
★ 510
microsoft
microsoft/win-dev-skills

WinDbg 虚拟内存耗尽分析

windbg-user-virtual-memory-exhaustion

当原生应用、服务或用户态驱动宿主程序分配失败时使用;用于区分虚拟地址(VA)耗尽、碎片化和提交内存(commit)压力。不适用于托管 .NET 堆增长、仅凭单个快照证明内存泄漏,或内存损坏场景。

软件开发工程师调试与故障排查
★ 510
microsoft
microsoft/win-dev-skills

WinDbg TTD 时序反向调试分析

windbg-user-ttd-reverse-debugging-triage

当应用、服务或用户态驱动宿主程序有 TTD(Time Travel Debugging)录制,且需要追溯早期的调用、写入或对象生命周期时使用。不适用于内核回放,也不适用于从普通转储文件获取历史记录。

软件开发工程师调试与故障排查
★ 510
microsoft
microsoft/win-dev-skills

WinDbg 用户态堆损坏排查

windbg-user-heap-corruption-investigation

当应用、服务或用户态驱动宿主程序堆分配失败,或 Application Verifier 检测到损坏时使用;可检查历史记录与内存边界。不适用于内核池损坏或普通的内存不足(OOM)。

软件开发工程师调试与故障排查
★ 510
microsoft
microsoft/win-dev-skills

用户态异常崩溃分诊

windbg-user-exception-triage

当本机 C/C++ 应用程序、服务或用户模式驱动程序主机(包括 UMDF)在转储文件或 WinDbg 会话中因结构化异常崩溃时使用,包括托管进程内的本机故障。不适用于托管 .NET 异常、WinUI/XAML 应用错误或内核错误检查(bugcheck)。

软件开发工程师调试与故障排查
★ 510