Subject: bug#54715: 28.0.92; crash when X server died

From: Ken Raeburn <[email-masked]>
Date: Tue, 05 Apr 2022 15:10:45 -0400

Po Lu <[email-masked]> writes:

> :0 and :0.0 are different X servers from the point of view of Xlib.
> Don't mix up display names like that: it just wastes display
> connections.

I haven’t been, intentionally.  I think the GNOME environment is doing
it somewhere.  Emacs is launched as one of my startup applications;
emacsclient is run via an icon in the top bar on my screen, or a global
key binding, or, occasionally, from a Firefox plugin.

> Yes, thanks.  I think the problem is that selected_frame is dead.  But
> if my reading of the code is correct, x_connection_closed calls
> delete_frame on all the frames on the disconnected terminal before
> Fkill_emacs is called (BTW, is that really right if Emacs is running as
> a daemon?),

To clarify: I used to run Emacs as a daemon (which would’ve been
relevant if it meant there was another, invisible terminal frame), but
apparently I stopped a while ago.  That’s what I meant that my use of it
had “fallen by the wayside”.  (Perhaps I should’ve just not mentioned
it.)  So with both instances of the local display connection dead at the
same time, there are no working frames left.

Eli wrote:
>> My guess would be that Ken's kill-emacs-hooks were called when the X
>> server died, and one of those hooks is unsafe, in that it causes
>> redisplay.

In server-start, hooks are added to kill-emacs-hook and
delete-frame-functions, among others; tramp-dump-connection-properties
and org-babel-remove-temporary-directory are also on the list.  But
server-force-stop appears in the stack trace.  It calls server-start,
which calls delete-process, which calls redisplay_preserve_echo_area.

Ken