Subject: 24.5; emacs --daemon hangs randomly when emacsclient -c used repeatedly

From: "Robert Lange" <[email-masked]>
Date: Mon, 09 May 2016 16:32:31 -0400

As stated in the title, I have been trying to use Emacs in daemon mode, however after a number of invocations of `emacsclient -c` the emacs daemon process hangs (not crashes) and I have to manually kill it.

I use Emacs (Lucid toolkit) on Debian Jessie at home and Ubuntu 14.04 at work. I experience the problem on both distributions using the distribution packages. I have compiled and debugged against the latest unmodified tarball of Emacs from GNU just to ensure that there were no distribution-specific patches causing the problem.

My problem is very similar to emacs bug #5802, except that bug was "fixed" by switching to use Emacs compiled with the Lucid toolkit, whereas my bug is still present even in Lucid.

To replicate:

Compile the latest GNU 24.5.1 source tarball using:

CFLAGS='-O0 -g3' ./configure --enable-checking='yes,glyphs' --enable-check-lisp-object-type --with-x-toolkit=lucid
make
cd src/
gdb ./emacs
 (gdb) run -Q -nw -f server-start

In a separate terminal:

x=0; while emacsclient -c; do x=$(( $x + 1 )); done; echo "Created $x windows before crash."

Close each Emacs client window after it appears. Eventually (it seems to average about 5 tries) Emacs will hang with a partially-drawn window. No interaction with the UI is possible. At that point in another terminal I execute:

ps -ef | grep emacs
kill -TSTP <emacs pid>

Returning to the original terminal containing GDB, I now execute:

bt

And get this output:

-----

#0 require_socket (dpy=0xf98ba0) at ../../src/xcb_io.c:60
#1 0x00007ffff5fb8b0e in poll_for_event (dpy=dpy@entry=0xf98ba0) at ../../src/xcb_io.c:251
#2 0x00007ffff5fb8cfc in poll_for_response (dpy=dpy@entry=0xf98ba0) at ../../src/xcb_io.c:289
#3 0x00007ffff5fb9147 in _XReadEvents (dpy=dpy@entry=0xf98ba0) at ../../src/xcb_io.c:424
#4 0x00007ffff5fa1751 in XIfEvent (dpy=0xf98ba0, event=event@entry=0x7fffffff83f0, predicate=predicate@entry=0x7ffff5fe7790 <_CheckCMEvent>, arg=arg@entry=0xf50340 "\200\365*\366\377\177")
 at ../../src/IfEvent.c:68
#5 0x00007ffff5fe7f24 in _XimXRead (im=0xf50340, recv_buf=0x7fffffff8dd0 "", buf_len=2048, ret_len=0x7fffffff851c) at ../../../../modules/im/ximcp/imTrX.c:476
#6 0x00007ffff5fe8b80 in _XimReadData (im=im@entry=0xf50340, len=len@entry=0x7fffffff857e, buf=buf@entry=0x7fffffff8dd0 "", buf_size=buf_size@entry=2048) at ../../../../modules/im/ximcp/imTransR.c:165
#7 0x00007ffff5fe8e71 in _XimRead (im=im@entry=0xf50340, len=len@entry=0x7fffffff85ce, buf=buf@entry=0x7fffffff8dd0 "", buf_size=buf_size@entry=2048, 
 predicate=predicate@entry=0x7ffff5fd6c80 <_XimDestroyICCheck>, arg=arg@entry=0x161a370 " \365*\366\377\177") at ../../../../modules/im/ximcp/imTransR.c:235
#8 0x00007ffff5fd70e8 in _XimProtoDestroyIC (xic=0x161a370) at ../../../../modules/im/ximcp/imDefIc.c:914
#9 0x00007ffff5fc58d2 in XDestroyIC (ic=0x161a370) at ../../../src/xlibi18n/ICWrap.c:265
#10 0x000000000054c6d6 in free_frame_xic (f=0x139e798) at xfns.c:2087
#11 0x00000000005455c5 in x_free_frame_resources (f=0x139e798) at xterm.c:9275
#12 0x0000000000545c11 in x_destroy_window (f=0x139e798) at xterm.c:9383
#13 0x000000000042826b in delete_frame (frame=..., force=...) at frame.c:1387
#14 0x0000000000541ff3 in x_connection_closed (dpy=0xf98ba0, error_message=0x7fffffff9940 "X protocol error: BadPixmap (invalid Pixmap parameter) on protocol request 55") at xterm.c:7635
#15 0x00000000005422b7 in x_error_quitter (display=0xf98ba0, event=0x7fffffff9af0) at xterm.c:7747
#16 0x0000000000542209 in x_error_handler (display=0xf98ba0, event=0x7fffffff9af0) at xterm.c:7717
#17 0x00007ffff5fbb54b in _XError (dpy=dpy@entry=0xf98ba0, rep=rep@entry=0xf76d70) at ../../src/XlibInt.c:1463
#18 0x00007ffff5fb85e7 in handle_error (dpy=0xf98ba0, err=0xf76d70, in_XReply=<optimized out>) at ../../src/xcb_io.c:213
#19 0x00007ffff5fb8695 in handle_response (dpy=dpy@entry=0xf98ba0, response=0xf76d70, in_XReply=in_XReply@entry=1) at ../../src/xcb_io.c:325
#20 0x00007ffff5fb9578 in _XReply (dpy=dpy@entry=0xf98ba0, rep=rep@entry=0x7fffffff9cb0, extra=extra@entry=0, discard=discard@entry=0) at ../../src/xcb_io.c:627
#21 0x00007ffff5faf4cf in XQueryColor (dpy=0xf98ba0, cmap=32, def=0x7fffffff9d10) at ../../src/QuColor.c:49
#22 0x00007ffff6b8c50c in Xaw3dComputeTopShadowRGB () from /usr/lib/x86_64-linux-gnu/libXaw3d.so.6
#23 0x00007ffff6b8c600 in ?? () from /usr/lib/x86_64-linux-gnu/libXaw3d.so.6
#24 0x00007ffff6b8ca6a in ?? () from /usr/lib/x86_64-linux-gnu/libXaw3d.so.6
#25 0x00007ffff66f1afc in CallInitialize (class=0x7ffff6dae960 <threeDClassRec>, req_widget=req_widget@entry=0x7fffffff9f20, new_widget=new_widget@entry=0x1604c60, args=args@entry=0x7fffffffa3f0, 
 num_args=3) at ../../src/Create.c:226
#26 0x00007ffff66f1ac6 in CallInitialize (class=0x7ffff6dac1c0 <scrollbarClassRec>, req_widget=req_widget@entry=0x7fffffff9f20, new_widget=new_widget@entry=0x1604c60, args=args@entry=0x7fffffffa3f0, 
 num_args=num_args@entry=3) at ../../src/Create.c:221
#27 0x00007ffff66f2427 in xtCreate (name=name@entry=0x703028 "verticalScrollBar", class=class@entry=0x0, widget_class=widget_class@entry=0x7ffff6dac1c0 <scrollbarClassRec>, parent=parent@entry=0x10506b0, 
 default_screen=0xfad8e0, args=args@entry=0x7fffffffa3f0, num_args=num_args@entry=3, typed_args=typed_args@entry=0x0, num_typed_args=num_typed_args@entry=0, parent_constraint_class=0x0, 
 post_proc=post_proc@entry=0x7ffff66f1b40 <widgetPostProc>) at ../../src/Create.c:416
#28 0x00007ffff66f2840 in _XtCreateWidget (name=name@entry=0x703028 "verticalScrollBar", widget_class=widget_class@entry=0x7ffff6dac1c0 <scrollbarClassRec>, parent=parent@entry=0x10506b0, 
 args=args@entry=0x7fffffffa3f0, num_args=num_args@entry=3, typed_args=typed_args@entry=0x0, num_typed_args=num_typed_args@entry=0) at ../../src/Create.c:570
#29 0x00007ffff66f2b0e in XtCreateWidget (name=0x703028 "verticalScrollBar", widget_class=0x7ffff6dac1c0 <scrollbarClassRec>, parent=0x10506b0, args=0x7fffffffa3f0, num_args=3) at ../../src/Create.c:589
#30 0x000000000053c417 in x_create_toolkit_scroll_bar (f=0x139e798, bar=0xfa2560) at xterm.c:4768
#31 0x000000000053c937 in x_scroll_bar_create (w=0x139f810, top=686, left=1, width=16, height=19) at xterm.c:4960
#32 0x000000000053d167 in XTset_vertical_scroll_bar (w=0x139f810, portion=0, whole=0, position=0) at xterm.c:5205
#33 0x000000000046b064 in set_vertical_scroll_bar (w=0x139f810) at xdisp.c:15905
#34 0x000000000046fcfa in redisplay_window (window=..., just_this_one_p=false) at xdisp.c:16947
#35 0x00000000004644f2 in redisplay_window_0 (window=...) at xdisp.c:14373
#36 0x00000000006173df in internal_condition_case_1 (bfun=0x4644b0 <redisplay_window_0>, arg=..., handlers=..., hfun=0x46447f <redisplay_window_error>) at eval.c:1372
#37 0x000000000046445d in redisplay_windows (window=...) at xdisp.c:14353
#38 0x0000000000463204 in redisplay_internal () at xdisp.c:13949
#39 0x0000000000463db4 in redisplay_preserve_echo_area (from_where=12) at xdisp.c:14206
#40 0x0000000000674157 in wait_reading_process_output (time_limit=30, nsecs=0, read_kbd=-1, do_display=true, wait_for_cell=..., wait_proc=0x0, just_wait_proc=0) at process.c:4821
#41 0x0000000000422d0c in sit_for (timeout=..., reading=true, display_option=1) at dispnew.c:5867
#42 0x0000000000576bff in read_char (commandflag=1, map=..., prev_event=..., used_mouse_menu=0x7fffffffd7f5, end_time=0x0) at keyboard.c:2810
#43 0x00000000005858f4 in read_key_sequence (keybuf=0x7fffffffda20, bufsize=30, prompt=..., dont_downcase_last=false, can_return_switch_frame=true, fix_current_buffer=true, prevent_redisplay=false)
 at keyboard.c:9089
#44 0x0000000000573161 in command_loop_1 () at keyboard.c:1453
#45 0x000000000061726e in internal_condition_case (bfun=0x572d8a <command_loop_1>, handlers=..., hfun=0x57253d <cmd_error>) at eval.c:1348
#46 0x0000000000572a28 in command_loop_2 (ignore=...) at keyboard.c:1178
#47 0x00000000006166f1 in internal_catch (tag=..., func=0x572a05 <command_loop_2>, arg=...) at eval.c:1112
#48 0x00000000005729dc in command_loop () at keyboard.c:1157
#49 0x0000000000572069 in recursive_edit_1 () at keyboard.c:778
#50 0x0000000000572239 in Frecursive_edit () at keyboard.c:849
#51 0x000000000057017b in main (argc=5, argv=0x7fffffffdde8) at emacs.c:1642

Lisp Backtrace:
"redisplay_internal (C function)" (0xd553f0)

-----

In GNU Emacs 24.5.1 (x86_64-unknown-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2016-05-09 on vistar-rlange
Windowing system distributor `The X.Org Foundation', version 11.0.11702000
System Description: Ubuntu 14.04.4 LTS

Configured using:
 `configure --enable-checking=yes,glyphs --enable-check-lisp-object-type
 --with-x-toolkit=lucid 'CFLAGS=-O0 -g3''

Important settings:
 value of $LC_COLLATE: C
 value of $LC_TIME: en_DK.UTF-8
 value of $LANG: en_US.UTF-8
 value of $XMODIFIERS: @im=ibus
 locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
 tooltip-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
 auto-composition-mode: t
 auto-encryption-mode: t
 auto-compression-mode: t
 line-number-mode: t
 transient-mark-mode: t

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Making completion list...

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util
help-fns mail-prsvr mail-utils help-mode easymenu time-date tooltip
electric uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
lisp-mode prog-mode register page menu-bar rfn-eshadow timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cham
georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese hebrew greek romanian slovak czech european ethiopic
indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple
abbrev minibuffer nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote make-network-process
dbusbind gfilenotify dynamic-setting system-font-setting
font-render-setting x-toolkit x multi-tty emacs)

Memory information:
((conses 16 73075 4517)
 (symbols 48 17654 0)
 (miscs 40 41 114)
 (strings 32 9912 3852)
 (string-bytes 1 266512)
 (vectors 16 9616)
 (vector-slots 8 388153 15866)
 (floats 8 68 135)
 (intervals 56 205 4)
 (buffers 960 12)
 (heap 1024 18602 895))