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

From: Zhengyi Fu <[email-masked]>
Date: Tue, 02 Sep 2025 14:18:58 +0800

Hi Emacs maintainers,

I have been suffering from this bug for a few weeks.

I spent a few days finding minimal steps to reproduce the bug:

- Install diff-hl and magit
- Set `diff-hl-update-async' to t and enable global-diff-hl-mode
- Enable server-mode

- Open a file in a git repo, make some changes and save it
- Run `magit-stage-buffer-file' to stage the changes
- Run `revert-buffer' in the file buffer, and make sure the diff-hl
  fringes are displayed
- Run `magit-commit-create'

At this moment, a COMMIT_EDITMSG buffer should appear.  But actually
sometimes no buffer appears.

If you run `list-processes', you can see that the git process and the
server connection are all there, as shown below.

git             542014  run     magit-process: emacs_test /dev/pts/1   Main         git --no-pager --literal-pathspecs -c core.preloadindex=true -c log.showSignature=false -c color.ui=false -c color.diff=false -c diff.noPrefix=false commit --
server          --      listen  --                        --           Main         (network server on /run/user/150425139/emacs/server)
server <2>      --      open    --                        --           Main         (network connection to t:/run/user/150425139/emacs/server)

The commit message buffer will pop up, if you eval
   (set-process-thread (get-process "server <2>") nil)

Further debugging through gdb revealed more details: the `thread'
member of the fd_callback_info entry for the server connection
references the diff-hl-async thread, which is already exited.

Simply adding a `set_proc_thread' in `server_accept_connections' like
the following seems to resolve the issue, but I'm not sure if this is
the correct fix.

diff --git a/src/process.c b/src/process.c
index d6efac5479d..326a36716d5 100644
--- a/src/process.c
+++ b/src/process.c
@@ -5115,6 +5115,8 @@ server_accept_connection (Lisp_Object server, int channel)
   /* Client processes for accepted connections are not stopped initially.  */
   if (!EQ (p->filter, Qt))
     add_process_read_fd (s);
+  set_proc_thread (p, current_thread);
+  
   if (s > max_desc)
     max_desc = s;



In GNU Emacs 31.0.50 (build 6, x86_64-pc-linux-gnu, GTK+ Version
 3.24.41) of 2025-09-02 built on james-fu-ubuntu2404
Repository revision: b953dc679c53d8ae26770762bcb2601389146768
Repository branch: heads/master
Windowing system distributor 'Microsoft Corporation', version 11.0.12010000
System Description: Ubuntu 24.04.3 LTS

Configured using:
 'configure --without-all --with-threads --enable-checking 'CFLAGS=-O1
 -ggdb3 -pipe''

Configured features:
GLIB GMP PDUMPER SECCOMP THREADS X11 XIM XINERAMA XRANDR GTK3

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Fundamental

Minor modes in effect:
  global-git-commit-mode: t
  magit-auto-revert-mode: t
  auto-revert-mode: t
  server-mode: t
  global-diff-hl-mode: t
  diff-hl-mode: t
  straight-use-package-mode: t
  straight-package-neutering-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  minibuffer-regexp-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
/var/lib/domain_home/auth.hpicorp.net/fujames/.config/emacs/straight/build/transient/transient hides /var/lib/domain_home/auth.hpicorp.net/fujames/src/emacs_test/lisp/transient
/var/lib/domain_home/auth.hpicorp.net/fujames/.config/emacs/straight/build/seq/seq hides /var/lib/domain_home/auth.hpicorp.net/fujames/src/emacs_test/lisp/emacs-lisp/seq
/var/lib/domain_home/auth.hpicorp.net/fujames/.config/emacs/straight/build/compat/compat hides /var/lib/domain_home/auth.hpicorp.net/fujames/src/emacs_test/lisp/emacs-lisp/compat

Features:
(shadow sort mail-extr emacsbug lisp-mnt bug-reference thingatpt
help-fns radix-tree cl-print debug backtrace find-func
display-line-numbers face-remap magit-submodule magit-blame magit-stash
magit-reflog magit-bisect magit-push magit-pull magit-fetch magit-clone
magit-remote magit-commit magit-sequence magit-notes magit-worktree
magit-tag magit-merge magit-branch magit-reset magit-files magit-refs
magit-status magit package url-handlers magit-repos magit-apply
magit-wip magit-log which-func imenu magit-diff smerge-mode diff
git-commit magit-core magit-autorevert autorevert filenotify
magit-margin magit-transient magit-process with-editor shell pcomplete
comint ansi-osc ansi-color magit-mode transient pp edmacro kmacro
browse-url xdg url url-proxy url-privacy url-expand url-methods
url-history url-cookie generate-lisp-file url-domsuf url-util url-parse
auth-source icons json map url-vars benchmark magit-git magit-base
magit-section format-spec cursor-sensor crm llama eieio byte-opt
eieio-core cond-let compat server vc-git files-x diff-hl log-view
log-edit message sendmail mailcap yank-media puny dired dired-loaddefs
rfc822 mml mml-sec password-cache epa derived epg rfc6068 epg-config
gnus-util text-property-search time-date mm-decode mm-bodies mm-encode
mail-parse rfc2231 rfc2047 rfc2045 mm-util ietf-drums mail-prsvr
mailabbrev mail-utils gmm-utils mailheader ring add-log pcvs-util vc-dir
ewoc vc vc-dispatcher diff-mode track-changes easy-mmode magit-autoloads
pcase with-editor-autoloads transient-autoloads magit-section-autoloads
llama-autoloads cond-let-autoloads compat-autoloads info seq-autoloads
diff-hl-autoloads finder-inf straight-autoloads cl-seq cl-extra
help-mode straight subr-x cl-macs gv cl-loaddefs cl-lib bytecomp
byte-compile rmc iso-transl tooltip cconv eldoc paren electric uniquify
ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win
term/common-win x-dnd touch-screen tool-bar dnd fontset image regexp-opt
fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode
register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer nadvice seq simple cl-generic indonesian philippine
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads dynamic-setting gtk x-toolkit x multi-tty move-toolbar
make-network-process tty-child-frames emacs)

Memory information:
((conses 16 161628 25408) (symbols 48 16281 0) (strings 32 52533 3112)
 (string-bytes 1 1564345) (vectors 16 32763)
 (vector-slots 8 308800 12722) (floats 8 75 448) (intervals 56 559 0)
 (buffers 984 21))