The first problem looked ordinary. The app would stop responding to anything: the tray
would not open, no global shortcut fired, and the log simply stopped mid-session. Restarting
fixed it. Task Manager reported Responding: true the entire time, with every
window alive and every webview idle.
The second I treated as unrelated, because it was not about my app at all. Some evenings the mouse would go dead. Not everywhere. I could alt-tab, I could click the taskbar, I could play Overwatch. I could not click anything in my browser, or Discord, or the Claude desktop app. I found a workaround by accident: triggering a UAC prompt cleared it every time.
That list is the whole diagnosis, and I read it as noise for a month.
What the selectivity meant
Chromium apps dead, games and the shell alive. Every item on that list has the same explanation:
- Brave, Discord and the Claude app are all Chromium, and all register drop targets.
During a drag they receive
IDropTargetcallbacks instead of clicks. - Overwatch reads raw input, which bypasses mouse capture entirely.
- The taskbar sits in a protected band and answers drags anyway.
- UAC switches to the secure desktop, which cancels any drag in progress. That is why my accidental workaround worked.
All four are explained by one fact: the entire desktop was in a drag state, and had been since I last dragged a capture out of my own app.
Two fixes that were wrong
I shipped two releases against the first problem before I understood any of this.
One fixed a busy-spin in the hotkey receiver: a recv() loop written as
if let Ok(...) inside a bare loop with no else branch. A
disconnected channel returns an error immediately and forever, so one dead sender turns that
into a hot loop that logs nothing.
The next fixed a flag that mirrored a window’s visibility. The frontend could hide that window in five places and the backend cleared the flag in one, so it stayed true for the rest of the session and a 60 Hz poll ran forever on the main thread.
Both were real bugs. I could explain in detail how each one produced exactly the symptom I was seeing. Neither of them was this. The report came back on both releases.
A plausible mechanism that explains the symptom is not the mechanism.
The measurement that told them apart
What I should have looked at, and did not, was one column: the split between user time and kernel time on the thread burning the CPU.
84% kernel, 2.2% user.
A flood of work posted to the main thread sixty times a second burns user time. Both of the bugs I had already fixed produced that shape. A thread spinning on an empty message queue burns kernel time. This was the second shape, and it had been the second shape all along.
Finding it from outside the process
Once the shape was clear, identifying it took about a minute, with no debugger and without touching the running app until the very end.
- Per-thread CPU finds the main thread. Its start time matches the process’s to the millisecond.
- Suspend it and read its context. The instruction pointer sits at
CONTEXT+0xF8. - Map that address to a module. Twenty-four samples out of twenty-four landed in
win32u.dll+0x12E4.GetProcAddressputsNtUserPeekMessage’s stub at0x12D0and the next export at0x12F0, so the address is inside it. GetGUIThreadInforeports which window holds the mouse capture.GetClassNameWon it returnedCLIPBRDWNDCLASS, the window OLE uses forDoDragDrop.GetAsyncKeyStateconfirmed no mouse button was down.
A drag was running with nobody dragging.
DoDragDrop runs its own modal message loop on the calling thread and
holds the mouse capture until the drag ends. So the main thread never returned to the
framework’s event loop, which is why the tray and every global shortcut died, and why
the process still reported healthy: it was pumping messages the whole time, just not mine.
Proving it, rather than believing it
Inference is cheap, and I had already been confidently wrong twice. So I posted a single
VK_ESCAPE to that window.
The thread went from 82.8% of a core to 0.4%, moved from Running to Wait, released the capture, and the log started writing again. Nothing was restarted, and the mouse came back everywhere.
The fix, and the number not to tune
There is now a watchdog that notices the main thread sitting in that state with no button held, and cancels the drag. Two constraints on it matter more than the rest of the code:
- It cancels through
QueryContinueDrag, never by forcing the capture away. Taking the capture back would leave OLE believing a drag is still running, which trades one bad state for a worse one. - It waits one second if the thread is spinning, and five if it is
blocked. Releasing the button does not end a drag.
DoDragDropthen callsIDropTarget::Dropon the receiving app and keeps the capture until that call returns, so a slow target legitimately holds it with no button down, and the thread blocks while it waits. My first draft used 1.5 seconds for both and would have cancelled real drops. A wedged drag spins instead, and every second of that is a dead desktop, so it gets one. Erring long costs somebody a few seconds. Erring short costs them their file.
The feature that caused this had shipped 1,064 commits earlier, and it was never specific to my machine. Anyone who dragged a file out of the app could hit it, on any Windows box.
The general shape
The bug itself was one modal loop that did not exit. What made it take three attempts was that I kept explaining the symptom instead of measuring it. Twice I found a genuine bug that could have produced what I was seeing, fixed it, shipped it, and watched the report come back.
The question is not whether your theory explains the symptom. It is what measurement would tell your theory apart from the other one.
Here that measurement was a single column of kernel time against user time, and it was on screen the entire time I was guessing.