Subject: bug#25247: 26.0.50; Concurrency crashes

From: Eli Zaretskii <[email-masked]>
Date: Fri, 23 Dec 2016 16:14:28 +0200

> From: Tino Calancha <[email-masked]>
> Cc: [email-masked], Tino Calancha <[email-masked]>, [email-masked]
> Date: Fri, 23 Dec 2016 20:32:14 +0900
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> I run
> run -r -Q -l /tmp/test.el
> with /tmp/test.el:
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (defun mytest ()
>   (dotimes (n 10)
>     (sleep-for 0.5)))
> 
> (defun run-test ()
>   (dotimes (_ 50)
>     (make-thread #'mytest)))
> 
> (run-test)
> 
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> Then i splitted windows, called a few times
> (run-test)
> and visited *Buffer List* before getting a crash.
> 
> the threads showing "really_call_select" in their backtraces are
> 1, and 155-204 (inclusive);  all but thread 158 have
> context_acquired = false
> The thread 158 is the one rising the exception, and it has
> context_acquired = true.

Thanks, this means that code in xgselect.c is doing its job well.  If
you ever again succeed in reproducing the abort in unblock_input_to,
due to level being negative, please do the same sequence of GDB
commands, and see if context_acquired is true in more than one thread.

> Thread 158 (Thread 0x7fff343f9700 (LWP 29195)):
> #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:58
> #1  0x00007fffefa9940a in __GI_abort () at abort.c:89
> #2  0x00007fffefa90e47 in __assert_fail_base (fmt=<optimized out>, assertion=assertion@entry=0x7ffff493fc00 "!xcb_xlib_threads_sequence_lost", file=file@entry=0x7ffff493fa6b "../../src/xcb_io.c", line=line@entry=259, function=function@entry=0x7ffff493fea8 "poll_for_event") at assert.c:92
> #3  0x00007fffefa90ef2 in __GI___assert_fail (assertion=0x7ffff493fc00 "!xcb_xlib_threads_sequence_lost", file=0x7ffff493fa6b "../../src/xcb_io.c", line=259, function=0x7ffff493fea8 "poll_for_event") at assert.c:101
> #4  0x00007ffff48cd77a in ?? () from /usr/lib/x86_64-linux-gnu/libX11.so.6
> #5  0x00007ffff48cd82b in ?? () from /usr/lib/x86_64-linux-gnu/libX11.so.6
> #6  0x00007ffff48cdb1d in _XEventsQueued () from /usr/lib/x86_64-linux-gnu/libX11.so.6
> #7  0x00007ffff48bf7e7 in XPending () from /usr/lib/x86_64-linux-gnu/libX11.so.6
> #8  0x00007ffff6712cee in ?? () from /usr/lib/x86_64-linux-gnu/libgdk-3.so.0
> #9  0x00007ffff5039edd in g_main_context_prepare () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
> #10 0x00007ffff503a91b in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
> #11 0x00007ffff503aab7 in g_main_context_pending () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
> #12 0x000000000070fff0 in xg_select (fds_lim=14, rfds=0x7fff343f8170, wfds=0x7fff343f80f0, efds=0x0, timeout=0x7fff343f80d0, sigmask=0x0) at xgselect.c:160
> #13 0x00000000006e031a in really_call_select (arg=0x7fff343f7e70) at thread.c:520

This seems to say that we somehow still call X from more than one
thread.  I don't understand how this could happen, since sleep-for
doesn't enter redisplay, at least AFAIK.

Could it be that g_main_context_default or g_main_context_acquire or
pselect itself calls X via some GTK hook?  Hmm...  Tino, is it
possible for you to try this again, but this time with Emacs in X
synchronous mode?  The file etc/DEBUG describes 2 ways of doing that
under "If you encounter X protocol errors".  Maybe this way we will
get the X error in a different place, which will give a hint about
what's going on.

Failing that, I hope the changes that Ken is testing will fix this.

Thanks for collecting and posting all this data, Tino.