Subject: bug#52414: backtrace when emacs get to stuck

From: Eli Zaretskii <[email-masked]>
Date: Sat, 11 Dec 2021 17:26:42 +0200

> Date: Sat, 11 Dec 2021 21:35:19 +0800
> From: "[email-masked]" <[email-masked]>
> 
> main thread bt:
> 
> #0  0x00007ffc20370764 in ntdll!ZwWaitForAlertByThreadId ()
>    from C:\Windows\SYSTEM32\ntdll.dll
> (gdb) bt
> #0  0x00007ffc20370764 in ntdll!ZwWaitForAlertByThreadId ()
>    from C:\Windows\SYSTEM32\ntdll.dll
> #1  0x00007ffc2033379d in ntdll!RtlWaitOnAddress ()
>    from C:\Windows\SYSTEM32\ntdll.dll
> #2  0x00007ffc20333652 in ntdll!RtlWaitOnAddress ()
>    from C:\Windows\SYSTEM32\ntdll.dll
> #3  0x00007ffc2033346d in ntdll!RtlWaitOnAddress ()
>    from C:\Windows\SYSTEM32\ntdll.dll
> #4  0x00007ffc202ffcb4 in ntdll!RtlEnterCriticalSection ()
>    from C:\Windows\SYSTEM32\ntdll.dll
> #5  0x00007ffc202ffae2 in ntdll!RtlEnterCriticalSection ()
>    from C:\Windows\SYSTEM32\ntdll.dll
> #6  0x00007ffc1f7ac6ad in msvcrt!_setmode ()
>    from C:\Windows\System32\msvcrt.dll
> #7  0x00007ffc1f7aaccd in msvcrt!_close () from C:\Windows\System32\msvcrt.dll
> #8  0x00007ff7e7bfac26 in sys_close (fd=5) at w32.c:8613
> #9  0x00007ff7e7a868ea in posix_close (fd=5, flag=1) at sysdep.c:2439
> #10 0x00007ff7e7a86928 in emacs_close (fd=5) at sysdep.c:2457
> #11 0x00007ff7e7b741b5 in close_process_fd (fd_addr=0x1cc84de9e24)
>     at process.c:2040

Thanks.  We are trying to close a handle on which the reader thread
already started reading, so the OS doesn't let us delete it.

This whole pipe-process stuff is flaky on MS-Windows.  Patches to fix
it are welcome.