Subject: Re: bug#79367: 31.0.50; magit-commit sometimes doesn't work if diff-hl-update-async is t

From: Eli Zaretskii <[email-masked]>
Date: Sat, 06 Sep 2025 10:27:51 +0300

> From: Zhengyi Fu <[email-masked]>
> Cc: [email-masked],  [email-masked],  [email-masked]
> Date: Sat, 06 Sep 2025 13:35:49 +0800
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> >> From: Zhengyi Fu <[email-masked]>
> >> Cc: [email-masked],  [email-masked],  [email-masked]
> >> Date: Fri, 05 Sep 2025 21:36:16 +0800
> >> 
> >> Eli Zaretskii <[email-masked]> writes:
> >> 
> >> > Thanks, then please show the value of the offending descriptor which
> >> > causes the assertion violation.  For that, please run Emacs udner GDB,
> >> > perform the recipe that reproduces the problem, and then type these
> >> > GDB commands:
> >> >
> >> >  (gdb) frame 1
> >> >  (gdb) print p->infd
> >> >
> >> > and tell what that produces.
> >> 
> >> The p->infd value is 8.
> >
> > OK, please repeat this several times to make sure it's always 8.
> >
> > If it is, then let's try to see which code leaves the .thread field
> > uncleared.  Like this (please run from the src directory where you
> > have the 'emacs' executable you have built):
> >
> >   $ gdb ./emacs
> >   ...
> >   (gdb) break process.c:8731
> >   (gdb) run
> >
> > Emacs will start and stop in init_process_emacs, on line 8731 of
> > process.c.  Then:
> >
> >   (gdb) watch fd_callback_info[8].thread
> >   (gdb) commands
> >    > bt 5
> >    > continue
> >    > end
> >   (gdb) continue
> >
> > The above sets a watchpoint which will stop Emacs each time we assign
> > some value to fd_callback_info[8].thread, and GDB will then show the
> > first 5 frames of the call-stack, then continue.  Now run your recipe,
> > until it gets SIGABRT, and post everything GDB produced until that
> > point.  I hope that will tell us which code fails to clear the .thread
> > member.
> >
> > Thanks.
> 
> The fd is 8 when running Emacs in terminal.
> The fd is always 16 when running Emacs in X11.

Thanks, please try the patch below, instead of the incorrect one I
asked you to try before:

diff --git a/src/process.c b/src/process.c
index fa003c2..736098f 100644
--- a/src/process.c
+++ b/src/process.c
@@ -4831,7 +4831,11 @@ deactivate_process (Lisp_Object proc)
   /* Beware SIGCHLD hereabouts.  */
 
   for (i = 0; i < PROCESS_OPEN_FDS; i++)
-    close_process_fd (&p->open_fd[i]);
+    {
+      fd_callback_info[p->open_fd[i]].thread = NULL;
+      fd_callback_info[p->open_fd[i]].waiting_thread = NULL;
+      close_process_fd (&p->open_fd[i]);
+    }
 
   inchannel = p->infd;
   eassert (inchannel < FD_SETSIZE);