Subject: process/thread interaction causes infinite hang in url-copy-file

From: Tom Gillespie <[email-masked]>
Date: Sun, 10 Jul 2022 14:26:08 -0700

This is a bug that appears to be caused by calling set-process-thread
on some process, allowing that process to finish and be cleaned up, and
then trying to wait on some other process called at a later point.

While the issue appears when calling url-copy-file, I suspect that
other functions that create a process and then wait for the result are
affected, but I have not identified any at this point in time.

I have attached process-thread-bugs.el that was also included in
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=56487 which includes
the repro for this issue.

The two functions of interest are enable-hang and maybe-trigger-hang.

Assuming process-thread-bugs.el is in the top level of the emacs repo
run the following commands to see the behavior in action

src/emacs -Q -batch -l ./process-thread-bugs.el wont hang 1

src/emacs -Q -batch -l ./process-thread-bugs.el will hang 1

src/emacs -Q -batch -l ./process-thread-bugs.el will hang 2

When calling will hang 1 or will hang 2, the behavior should be
obvious as a presumably infinite number of lines of "oh no" being
printed to stderr.