Subject: 23.1; Forcibly breaking 'emacsclient -c' X connections can crash emacs.

From: Nelson Elhage <[email-masked]>
Date: Fri, 7 Aug 2009 18:50:14 -0400 (EDT)

Steps to reproduce:
 (1) Run 'emacs --daemon' or 'emacs -nw'
 (2) M-x server-start
 (3) Run 'emacsclient -c'
 (4) Run 'xkill' and click on the Emacs X window
 (5) Run 'emacsclient -c' again

Expected behavior:

 Another emacs X window pops up.

Observed behavior:

 * A window pops up, but remains blank and non-responsive.
 * The 'emacs -nw' window outputs an infinite stream of
   (process:11200): GLib-WARNING (recursed) **: g_main_context_prepare() called recursively from within a source's check() or prepare() member

 At this point, 'emacsclient -t' still works properly, and killing the
 new '-c' session seems to usually stop the GLib spew.

I captured a backtrace of emacs, interrupted while it was spewing that
warning endlessly. I appear to have caught it while logging the error,
so hopefully the stack is relevant. This is 100% reproducible for me,
so I can happily provide other stack traces if they would be useful.

---------- CUT HERE ----------
#0  0xb7f32430 in __kernel_vsyscall ()
No symbol table info available.
#1  0xb776d053 in __write_nocancel () from /lib/tls/i686/cmov/libpthread.so.0
No symbol table info available.
#2  0xb77bc306 in write_string (fd=2, string=0x8de0360 "\n(emacs:19202): GLib-WARNING **: g_main_context_check() called recursively from within a source's check() or prepare() member.\n") at /build/buildd/glib2.0-2.20.1/glib/gmessages.c:130
No locals.
#3  0xb77bc78c in IA__g_log_default_handler (log_domain=0xb77ecf06 "GLib", log_level=<value optimized out>, message=0x8fbd018 "g_main_context_check() called recursively from within a source's check() or prepare() member.", unused_data=0x0) at /build/buildd/glib2.0-2.20.1/glib/gmessages.c:959
	level_prefix = "WARNING **\000\004\000\000\000(\ufffd\204\ufffd\ufffdW}\ufffd$\ufffd\204\ufffd\004*\177\ufffd\ufffd\ufffd\204\ufffd&\ufffd{\ufffd\030\ufffd\ufffd\b\ufffd\227\ufffd\b"
	string = (gchar *) 0x8de0360 "\n(emacs:19202): GLib-WARNING **: g_main_context_check() called recursively from within a source's check() or prepare() member.\n"
	gstring = (GString *) 0x8e1d5d0
	fd = 2
#4  0xb77bcb3f in IA__g_logv (log_domain=0xb77ecf06 "GLib", log_level=G_LOG_LEVEL_WARNING, format=0xb77f2a04 "g_main_context_check() called recursively from within a source's check() or prepare() member.", args1=0xbf84e2dc "\ufffd\ufffd\202\ufffd\u0422Q\b`\ufffd[\b\030\ufffd\204\ufffd2E{\ufffd\234\ufffd\204\ufffd4\ufffd\204\ufffdo\ufffd9\ufffdTC{\ufffd\002") at /build/buildd/glib2.0-2.20.1/glib/gmessages.c:483
	depth = 1
	domain = <value optimized out>
	data = (gpointer) 0x0
	log_func = (GLogFunc) 0xb77bc480 <IA__g_log_default_handler>
	domain_fatal_mask = 5
	test_level = G_LOG_LEVEL_WARNING
	was_recursion = 0
	i = <value optimized out>
#5  0xb77bcee6 in IA__g_log (log_domain=0xb77ecf06 "GLib", log_level=G_LOG_LEVEL_WARNING, format=0xb77f2a04 "g_main_context_check() called recursively from within a source's check() or prepare() member.") at /build/buildd/glib2.0-2.20.1/glib/gmessages.c:526
No locals.
#6  0xb77b561e in IA__g_main_context_check (context=0x851a2d0, max_priority=-1216652197, fds=0x8f62c00, n_fds=0) at /build/buildd/glib2.0-2.20.1/glib/gmain.c:2264
	source = <value optimized out>
	pollrec = <value optimized out>
	n_ready = <value optimized out>
	i = <value optimized out>
#7  0xb77b5fdd in g_main_context_iterate (context=0x851a2d0, block=0, dispatch=0, self=0x84f92e8) at /build/buildd/glib2.0-2.20.1/glib/gmain.c:2445
	max_priority = -1216652197
	timeout = 0
	some_ready = <value optimized out>
	nfds = 0
	allocated_nfds = <value optimized out>
	fds = (GPollFD *) 0x8f62c00
	__PRETTY_FUNCTION__ = "g_main_context_iterate"
#8  0xb77b6361 in IA__g_main_context_pending (context=0x851a2d0) at /build/buildd/glib2.0-2.20.1/glib/gmain.c:2476
	retval = <value optimized out>
#9  0xb7c936a1 in IA__gtk_events_pending () at /build/buildd/gtk+2.0-2.16.1/gtk/gtkmain.c:1283
	result = <value optimized out>
#10 0x080e1b25 in XTread_socket (terminal=0x85ba560, expected=1, hold_quit=0xbf84e6f4) at xterm.c:7263
	count = 0
#11 0x08124a0e in read_avail_input (expected=1) at keyboard.c:7093
	nr = <value optimized out>
	hold_quit = {
  kind = NO_EVENT, 
  code = 0, 
  part = scroll_bar_above_handle, 
  modifiers = 0, 
  x = 0, 
  y = 0, 
  timestamp = 0, 
  padding = {0x0, 0x0}, 
  frame_or_window = 0, 
  arg = 0
}
	next = (struct terminal *) 0x85aaa60
	nread = 0
	err = 0
	t = (struct terminal *) 0x85ba560
#12 0x08124b1a in handle_async_input () at keyboard.c:7335
	nread = 126
#13 0x08124ce4 in process_pending_signals () at keyboard.c:7351
No locals.
#14 0x081c56ad in wait_reading_process_output (time_limit=30, microsecs=0, read_kbd=-1, do_display=1, wait_for_cell=137932057, wait_proc=0x0, just_wait_proc=0) at process.c:4566
	timeout_reduced_for_timers = 0
	channel = 6
	nfds = 1
	Available = {
  fds_bits = {256, 0 <repeats 31 times>}
}
	Connecting = {
  fds_bits = {0 <repeats 32 times>}
}
	check_connect = 0
	check_delay = 0
	no_avail = 6
	xerrno = 4
	proc = 0
	timeout = {
  tv_sec = 27, 
  tv_usec = 359730
}
	end_time = {
  tv_sec = 1249684951, 
  tv_usec = 389145
}
	wait_channel = -1
	got_some_input = 1
#15 0x08057908 in sit_for (timeout=240, reading=1, do_display=1) at dispnew.c:6644
	sec = 30
	usec = 0
#16 0x08127477 in read_char (commandflag=1, nmaps=2, maps=0xbf84eda0, prev_event=137932057, used_mouse_menu=0xbf84ee50, end_time=0x0) at keyboard.c:2950
	tem0 = <value optimized out>
	delay_level = 30
	buffer_size = <value optimized out>
	c = 137932057
	local_getcjmp = {{
    __jmpbuf = {2, 138810852, 1, -1081807528, -837355840, -485490769}, 
    __mask_was_saved = 0, 
    __saved_mask = {
      __val = {1, 3756253275, 4294967295, 3213159564, 138845896, 3213159784, 135802329, 137961409, 8, 138845900, 0, 0, 0, 0, 0, 0, 0, 0, 139142245, 138270520, 138943313, 3213159656, 135762616, 138943313, 137932057, 137932057, 0, 0, 0, 0, 138943313, 138943313}
    }
  }}
	save_jump = {{
    __jmpbuf = {2, 138810852, 1, -1081807528, -837355840, -485490769}, 
    __mask_was_saved = 0, 
    __saved_mask = {
      __val = {1, 3756253275, 4294967295, 3213159564, 138845896, 3213159784, 135802329, 137961409, 8, 138845900, 3213159312, 3213159316, 3, 137887744, 3756253275, 137932057, 141166576, 138852921, 139142245, 138270520, 138943313, 3213159656, 135762616, 138943313, 137932057, 137932057, 0, 8192, 0, 0, 138943313, 138943313}
    }
  }}
	key_already_recorded = 0
	tem = 0
	save = <value optimized out>
	previous_echo_area_message = 137932057
	also_record = 137932057
	reread = 0
	polling_stopped_here = <value optimized out>
	orig_kboard = (struct kboard *) 0x85699d8
#17 0x08128a32 in read_key_sequence (keybuf=0xbf84ef04, bufsize=30, prompt=137932057, dont_downcase_last=0, can_return_switch_frame=1, fix_current_buffer=1) at keyboard.c:9460
	interrupted_kboard = (KBOARD *) 0x85699d8
	key = 137957916
	used_mouse_menu = 0
	echo_local_start = 0
	last_real_key_start = 0
	keys_local_start = 0
	local_first_binding = 0
	from_string = 137932057
	count = 2
	t = 0
	echo_start = 0
	keys_start = 0
	nmaps = 2
	nmaps_allocated = 2
	defs = (Lisp_Object * volatile) 0xbf84ed80
	submaps = (Lisp_Object * volatile) 0xbf84eda0
	orig_local_map = 140836941
	orig_keymap = 137932057
	localized_local_map = 0
	first_binding = 0
	first_unbound = 31
	mock_input = 0
	fkey = {
  parent = 138253677, 
  map = 138253677, 
  start = 0, 
  end = 0
}
	keytran = {
  parent = 137925501, 
  map = 137925501, 
  start = 0, 
  end = 0
}
	indec = {
  parent = 138253685, 
  map = 138253685, 
  start = 0, 
  end = 0
}
	shift_translated = 0
	delayed_switch_frame = 137932057
	original_uppercase = 32
	original_uppercase_position = -1
	starting_buffer = (struct buffer *) 0x8391218
	fake_prefixed_keys = 137932057
#18 0x0812a693 in command_loop_1 () at keyboard.c:1642
	cmd = <value optimized out>
	lose = 138474920
	nonundocount = 0
	keybuf = {137932105, -1081807034, 137932057, 0, 137932057, -1081806968, 135413816, 140940237, -1081807034, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1081807004, -1081807168, 0, -65536, 137932057, 138888001, -538714021, 0, 138474920, 138474904, -538714021}
	i = 138474920
	prev_modiff = 0
	prev_buffer = (struct buffer *) 0x0
	already_adjusted = 0
#19 0x08188870 in internal_condition_case (bfun=0x812a4b0 <command_loop_1>, handlers=137975193, hfun=0x8123f50 <cmd_error>) at eval.c:1512
	val = <value optimized out>
	c = {
  tag = 137932057, 
  val = 137932057, 
  next = 0xbf84f0b0, 
  gcpro = 0x0, 
  jmp = {{
      __jmpbuf = {0, 138474920, 138474904, -1081806728, -836790592, -154085969}, 
      __mask_was_saved = 0, 
      __saved_mask = {
        __val = {3086286836, 3070294640, 30, 3213160180, 3086205101, 140035264, 3213160092, 3074280011, 3075268596, 3075273024, 3086270536, 3213160128, 3074295222, 276967387, 3076992320, 8655230, 59, 3213160784, 3213160492, 3213160784, 3213160632, 135485316, 2, 3213160644, 3213160492, 0, 0, 0, 0, 0, 0, 0}
      }
    }}, 
  backlist = 0x0, 
  handlerlist = 0x0, 
  lisp_eval_depth = 0, 
  pdlcount = 2, 
  poll_suppress_count = 1, 
  interrupt_input_blocked = 0, 
  byte_stack = 0x0
}
	h = {
  handler = 137975193, 
  var = 137932057, 
  chosen_clause = 137932105, 
  tag = 0xbf84ef9c, 
  next = 0x0
}
#20 0x081234a5 in command_loop_2 () at keyboard.c:1359
	val = 126
#21 0x0818894a in internal_catch (tag=137971217, func=0x8123480 <command_loop_2>, arg=137932057) at eval.c:1248
	c = {
  tag = 137971217, 
  val = 137932057, 
  next = 0x0, 
  gcpro = 0x0, 
  jmp = {{
      __jmpbuf = {0, 138474920, 138474904, -1081806472, -836634944, -153956945}, 
      __mask_was_saved = 0, 
      __saved_mask = {
        __val = {0, 0, 0, 0, 0, 3075273192, 3075152686, 3075159464, 3075146958, 3075146778, 0, 0, 0, 3075273080, 177, 22, 0, 1, 139572448, 0, 138172384, 138170690, 137957912, 3213160808, 135764507, 138172385, 138170690, 137932057, 137957912, 137932081, 138170688, 0}
      }
    }}, 
  backlist = 0x0, 
  handlerlist = 0x0, 
  lisp_eval_depth = 0, 
  pdlcount = 2, 
  poll_suppress_count = 1, 
  interrupt_input_blocked = 0, 
  byte_stack = 0x0
}
#22 0x08123d9f in command_loop () at keyboard.c:1338
No locals.
#23 0x0812415b in recursive_edit_1 () at keyboard.c:953
	val = <value optimized out>
#24 0x081242a4 in Frecursive_edit () at keyboard.c:1015
	buffer = 137932057
#25 0x08119ee7 in main (argc=3, argv=0xbf84f584) at emacs.c:1852
	dummy = 140221632
	stack_bottom_variable = 8 '\b'
	do_initial_setlocale = 1
	skip_args = 1
	rlim = {
  rlim_cur = 8388608, 
  rlim_max = 18446744073709551615
}
	no_loadup = 0
	junk = 0x0
	dname_arg = 0x0
---------- END CUT ----------

In GNU Emacs 23.1.1 (i686-pc-linux-gnu, GTK+ Version 2.16.1)
 of 2009-07-30 on phanatique
Windowing system distributor `The X.Org Foundation', version 11.0.10600000
Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default-enable-multibyte-characters: t

Major mode: Python

Minor modes in effect:
  diff-auto-refine-mode: t
  iswitchb-mode: t
  shell-dirtrack-mode: t
  display-battery-mode: t
  display-time-mode: t
  window-number-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  global-auto-composition-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t

Recent input:
<triple-down-mouse-4> <triple-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <triple-down-mouse-4> <triple-mouse-4> 
<triple-down-mouse-4> <triple-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <triple-down-mouse-4> <triple-mouse-4> 
<triple-down-mouse-4> <triple-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <triple-down-mouse-4> <triple-mouse-4> 
<triple-down-mouse-4> <triple-mouse-4> <down-mouse-4> 
<mouse-4> <double-down-mouse-4> <double-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <triple-down-mouse-4> <triple-mouse-4> 
<triple-down-mouse-4> <triple-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <help-echo> <down-mouse-4> <mouse-4> 
<down-mouse-4> <mouse-4> <down-mouse-4> <mouse-4> <down-mouse-4> 
<mouse-4> <double-down-mouse-4> <double-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <down-mouse-4> <mouse-4> <down-mouse-4> 
<mouse-4> <down-mouse-4> <mouse-4> <double-down-mouse-4> 
<double-mouse-4> <down-mouse-4> <mouse-4> <down-mouse-4> 
<mouse-4> <double-down-mouse-4> <double-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <triple-down-mouse-4> <triple-mouse-4> 
<triple-down-mouse-4> <triple-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <triple-down-mouse-4> <triple-mouse-4> 
<triple-down-mouse-4> <triple-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <triple-down-mouse-4> <triple-mouse-4> 
<triple-down-mouse-4> <triple-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <triple-down-mouse-4> <triple-mouse-4> 
<triple-down-mouse-4> <triple-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <triple-down-mouse-4> <triple-mouse-4> 
<triple-down-mouse-4> <triple-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <triple-down-mouse-4> <triple-mouse-4> 
<triple-down-mouse-4> <triple-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <triple-down-mouse-4> <triple-mouse-4> 
<triple-down-mouse-4> <triple-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <triple-down-mouse-4> <triple-mouse-4> 
<triple-down-mouse-4> <triple-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <triple-down-mouse-4> <triple-mouse-4> 
<triple-down-mouse-4> <triple-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <triple-down-mouse-4> <triple-mouse-4> 
<triple-down-mouse-4> <triple-mouse-4> <triple-down-mouse-4> 
<triple-mouse-4> <down-mouse-5> <mouse-5> <down-mouse-5> 
<mouse-5> <down-mouse-4> <mouse-4> M-v C-c 3 M-v C-l 
C-n C-n C-e C-p C-p C-p C-p C-p C-p C-p C-c 1 C-s r 
e a d P l a n C-s C-n C-s r e a d I n i t P l a n C-s 
C-g C-c 2 C-c 3 C-a C-e C-c ` C-g C-g C-c 1 M-v C-l 
C-v C-c 3 C-v C-l <return> C-/ M-v C-v C-v C-v C-v 
C-l <down-mouse-4> <mouse-4> <down-mouse-4> <mouse-4> 
<down-mouse-4> <mouse-4> <double-down-mouse-4> <double-mouse-4> 
<down-mouse-4> <mouse-4> <double-down-mouse-4> <double-mouse-4> 
<down-mouse-4> <mouse-4> C-n C-n C-n C-c 1 M-< C-s 
U p d a t e C-n C-c 2 C-x b m a <return> M-< C-s U 
I <backspace> p d a t e C-s C-s C-s C-s C-s C-s C-s 
C-s C-s C-s C-s C-s C-s C-s C-n C-x 0 C-x + M-x r e 
p o r SPC b <backspace> e m <tab> b <tab> <return> 
C-g M-x s e r v e r SPC s t <tab> <M-backspace> <M-backspace> 
k i l l <tab> C-g M-p M-x M-p <return>

Recent messages:
Quit
Mark set [2 times]
Mark saved where search started [3 times]
Quit [3 times]
Undo!
Mark set
Mark saved where search started
Mark set
Mark saved where search started
Quit
Quit