From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: =?UTF-8?Q?Adam_Sj=C3=83=C2=B8gren_via_=22Emacs_development_discussions=2E?= Newsgroups: gmane.emacs.devel Subject: Re: long-standing GTK bug Date: Sun, 17 May 2020 13:40:38 +0200 Organization: koldfront - analysis & revolution, Copenhagen, Denmark Message-ID: <87ftbyokll.fsf@tullinup.koldfront.dk> References: <83zhbcg6s4.fsf@gnu.org> <87r1wng2ki.fsf@linaro.org> <83o8rrenn1.fsf@gnu.org> <87blnr6uck.fsf@tullinup.koldfront.dk> <87wo5kumkn.fsf_-_@tullinup.koldfront.dk> <86ftc5hc8j.fsf@gmail.com> <87d079io10.fsf@tullinup.koldfront.dk> Reply-To: =?UTF-8?Q?Reply-to=3A_Adam_Sj=C3=83=C2=B8gren_=3Casjo=40koldfront=2Edk=3E?= =?UTF-8?Q?=0A?= Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="62652"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) To: emacs-devel@gnu.org Cancel-Lock: sha1:JhprfisqYUgAfGSCvGlopFz6ft4= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun May 17 13:42:12 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jaHgK-000GCF-Bu for ged-emacs-devel@m.gmane-mx.org; Sun, 17 May 2020 13:42:12 +0200 Original-Received: from localhost ([::1]:47548 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jaHgH-0000EK-T9 for ged-emacs-devel@m.gmane-mx.org; Sun, 17 May 2020 07:42:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49192) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jaHf1-0007gn-7N for emacs-devel@gnu.org; Sun, 17 May 2020 07:40:52 -0400 Original-Received: from ciao.gmane.io ([159.69.161.202]:38040) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jaHey-0001wG-Tb for emacs-devel@gnu.org; Sun, 17 May 2020 07:40:50 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1jaHev-000EuB-IN for emacs-devel@gnu.org; Sun, 17 May 2020 13:40:45 +0200 X-Injected-Via-Gmane: http://gmane.org/ OpenPGP: id=476630590A231909B0A0961A49D0746121BDE416; url=https://asjo.koldfront.dk/gpg.asc X-Face: )qY&CseJ?.:=8F#^~GcSA?F=9eu'{KAFfL1C3/A&:nE?PW\i65"ba0NS)97, Q(^@xk}n4Ou rPuR#V8I(J_@~H($[ym:`K_+]*kjvW>xH5jbgLBVFGXY:(#4P>zVBklLbdL&XxL\M)%T}3S/IS9lMJ ^St'=VZBR List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:250588 Archived-At: I wrote: > If you remove the workaround in frame.c and remove the call to > emacs_abort() when using GTK in x_connection_closed() in xterm.c, and > the connection to a display is terminated while Emacs has a window on > that display, you'll still get an endless stream of warnings from GLib, > i.e. "the GTK bug". I have been looking further into it, and I think I now understand what happens. Emacs calls gtk_events_pending(), which then continues to g_main_context_prepare(), in which a counter in the context structure, in_check_or_prepare, is incremented to detect recursive calls to this function in GLib. Before the counter is decremented again, the X-connection disappears, and X calls Emacs' error handler x_io_error_quitter(). The error handler closes the display¹, and Emacs then continues. But it doesn't return to the place in g_main_context_prepare(), so the counter isn't decremented. When Emacs then calls gtk_events_pending() again, GLib looks at the counter, and emits warnings about recursive calls. At least that is what I think is happening - gleaned from adding a breakpoint to delete_frame() and staring at this backtrace and the code in GLib²: #0 delete_frame (frame=0x555556183ba5, force=force@entry=0xa170) at frame.c:1902 #1 0x000055555559707e in x_connection_closed (dpy=dpy@entry=0x555556c58590, error_message=, error_message@entry=0x7fffffffcf40 "Connection lost to X server 'localhost:10.0'", ioerror=ioerror@entry=true) at lisp.h:1042 #2 0x00005555555971a9 in x_io_error_quitter (display=0x555556c58590) at xterm.c:10180 #3 0x00007ffff6aac20e in _XIOError () at /lib/x86_64-linux-gnu/libX11.so.6 #4 0x00007ffff6aa9985 in _XEventsQueued () at /lib/x86_64-linux-gnu/libX11.so.6 #5 0x00007ffff6a9b511 in XPending () at /lib/x86_64-linux-gnu/libX11.so.6 #6 0x00007ffff7435b6f in () at /lib/x86_64-linux-gnu/libgdk-3.so.0 #7 0x00007ffff6e1fd7f in g_main_context_prepare () at /lib/x86_64-linux-gnu/libglib-2.0.so.0 #8 0x00007ffff6e2072b in () at /lib/x86_64-linux-gnu/libglib-2.0.so.0 #9 0x00007ffff6e208c8 in g_main_context_pending () at /lib/x86_64-linux-gnu/libglib-2.0.so.0 #10 0x00007ffff7708f0e in gtk_events_pending () at /lib/x86_64-linux-gnu/libgtk-3.so.0 #11 0x000055555564c97d in XTread_socket (terminal=, hold_quit=0x7fffffffd200) at xterm.c:9398 To test my interpretation, I decided to decrement the counter in the context structure from inside x_connection_closed(), by adding: GMainContext *context; context = g_main_context_default(); // Try resetting recursion prevention counter: context->in_check_or_prepare = 0; before calling gdk_display_close() on the display that has disappeared³. This makes the endless stream of warnings not appear! However, my quick test required me to copy the struct _GMainContext definition from glib/gmain.c into xterm.c, which is not the correct way to go about this, I'm sure. I do feel that this is progress, though. Now we just need to figure out the right way to handle it. If that is for gdk_display_close() to reset the in_check_or_prepare counter, or if it is something that can be changed in Emacs, I don't know. I have updated the current GTK issue⁴ with my observations, but I'm hoping for some input from emacs-devel as well. Best regards, Adam ¹ If you change it from calling emacs_abort() to close the display, as I have, that is. ² https://github.com/GNOME/glib/blob/mainline/glib/gmain.c#L3530 ³ https://koldfront.dk/git/emacs/commit/?h=scratch/gtk-x-disconnect&id=94eea826b6aa69ecf94301b4da251059dc89212b ⁴ https://gitlab.gnome.org/GNOME/gtk/-/issues/2315 -- "When you grow up, it's not allowed." Adam Sjøgren "All the more reason I should do it *now*!" asjo@koldfront.dk