Case of frozen PeekMessage

Recently I was investigating why our application freezes during certain operations. After collecting few dump files, I found that every single time application freezes in quite old code that was written about 20 years ago. Loading documents could be quite long, and some person decided that it would be good idea if user can press Escape and cancel loading. To detect key press, that code calls something like this:
PeekMessage(Msg, CurrentFormHandle, WM_KeyFirst, WM_KeyLast, PM_Remove Or PM_NoYield)

Callstack looks like this:

win32u!NtUserPeekMessage+0x14
user32!_PeekMessage+0x43
user32!PeekMessageW+0x143

It looks quite innocent and I do not see any reason why it should hang. After some thinking I came with two theories:

  1. CurrentFormHandle returns invalid window handle that got reused by some thread that is sleeping
  2. Code that calls PeekMessage has infinite loop and PeekMessage is just took more time and appears in crash dumps.