Subject: Re: bug#18403: 24.4.50; emacsclient sometimes hangs on exit with Lucid GUI client

From: Dmitry Antipov <[email-masked]>
Date: Mon, 08 Sep 2014 12:45:46 +0400

On 09/08/2014 06:48 AM, Paul Eggert wrote:

> Thanks, I can confirm that the attached patch (which reverts that change) does fix
> the bug on the trunk for me (trunk bzr 117838). Dmitry, do you have any thoughts?

Argh.  It looks like we can't free XtDefaultFont, otherwise XtCloseDisplay causes
X protocol error, and poor handling of that causes a mess with normal fds listening
loop.  Thanks.

While debugging this issue, I noticed one more error:

Breakpoint 1, die (msg=0x717274 "errno != EBADF || fd < 0", file=0x7170e0 "../../trunk/src/sysdep.c", line=2408)
     at ../../trunk/src/alloc.c:7116
7116	  fprintf (stderr, "\r\n%s:%d: Emacs fatal error: assertion failed: %s\r\n",
(gdb) bt 10
#0  0x00000000005f6cee in die (msg=0x717274 "errno != EBADF || fd < 0", file=0x7170e0 "../../trunk/src/sysdep.c", line=2408)
     at ../../trunk/src/alloc.c:7116
#1  0x0000000000598469 in emacs_close (fd=8) at ../../trunk/src/sysdep.c:2408
#2  0x0000000000547834 in x_delete_terminal (terminal=0xfa0218) at ../../trunk/src/xterm.c:11381
#3  0x000000000051f8b6 in Fdelete_terminal (terminal=..., force=...) at ../../trunk/src/terminal.c:348
#4  0x00000000004290ba in delete_frame (frame=..., force=...) at ../../trunk/src/frame.c:1691
#5  0x0000000000429630 in Fdelete_frame (frame=..., force=...) at ../../trunk/src/frame.c:1801
#6  0x0000000000618c95 in Ffuncall (nargs=2, args=0x7fffd6a18ae0) at ../../trunk/src/eval.c:2815
#7  0x0000000000663e4a in exec_byte_code (bytestr=..., vector=..., maxdepth=..., args_template=..., nargs=1, args=0x7fffd6a193a0)
     at ../../trunk/src/bytecode.c:920
#8  0x00000000006194bd in funcall_lambda (fun=..., nargs=1, arg_vector=0x7fffd6a19398) at ../../trunk/src/eval.c:2980
#9  0x0000000000618e4e in Ffuncall (nargs=2, args=0x7fffd6a19390) at ../../trunk/src/eval.c:2861
#10 0x0000000000663e4a in exec_byte_code (bytestr=..., vector=..., maxdepth=..., args_template=..., nargs=1, args=0x7fffd6a19c30)
     at ../../trunk/src/bytecode.c:920

Steps to reproduce:

./src/emacs -Q --daemon
./lib-src/emacsclient -c

gdb -p [pid of daemon process]
b die
c

C-x C-x in client window
==> backtrace above

IIUC dpyinfo->connection is no longer valid after call to X(t)CloseDisplay (dpyinfo->display).
But this fd is still > 0, so we hit eassert at sysdep.c:2408:

eassert (errno != EBADF || fd < 0);

Since daemon runs in background, there is no way to see this error except using debugger.

Also note that the comment above emacs_close says do not use this function for non-negative
but closed descriptor.

Dmitry