Subject: bug#79201: 30.1.90; set-process-thread can permanently break fd_callback_info slots

From: Eli Zaretskii <[email-masked]>
Date: Sat, 09 Aug 2025 13:33:40 +0300

> Cc: [email-masked], [email-masked], [email-masked]
> Date: Fri, 08 Aug 2025 16:34:10 -0400
> From:  Spencer Baugh via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> Here's a patch to fix it by initializing these fields.

Thanks, but I don't think this is right.  First,
update_processes_for_thread_death clears the .thread member of
fd_callback_info of those processes that were locked to the dying
thread.  Second, wait_reading_process_output_unwind clears the
.waiting_thread member of fd_callback_info for all descriptors, when
we exit wait_reading_process_output (which is called by
accept-process-output).  And finally, IMO it is wrong for the add_*_fd
functions to overwrite these two members, because they are set and
reset by other functions, mainly those which compute the wait mask for
the pselect call.  add_*_fd should not touch these members.

I believe in this case update_processes_for_thread_death doesn't do
its job because your scenario kills the process before the thread
dies, and update_processes_for_thread_death only looks at the
processes that are in Vprocess_alist.  So it is possible that all
that's missing is that delete_read_fd and delete_write_fd (which are
called from deactivate_process) should clear the .thread member of
fd_callback_info corresponding to the process's input and output
descriptors.

If that doesn't fix the issue with your reproducer, please investigate
why, and let's take it from there.