After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 152023 - multi-threading problem in gnome-ice.c
multi-threading problem in gnome-ice.c
Status: RESOLVED FIXED
Product: libgnomeui
Classification: Deprecated
Component: general
CVS HEAD
Other All
: High major
: future
Assigned To: libgnomeui maintainers
libgnomeui maintainers
: 301754 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2004-09-06 23:02 UTC by Jean-Yves Lefort
Modified: 2006-02-28 22:01 UTC
See Also:
GNOME target: ---
GNOME version: 2.9/2.10


Attachments
fix (447 bytes, patch)
2004-09-06 23:03 UTC, Jean-Yves Lefort
needs-work Details | Review
demonstrates the bug (1.08 KB, application/octet-stream)
2004-09-07 22:39 UTC, Jean-Yves Lefort
  Details
backtrace (3.53 KB, text/plain)
2004-09-07 22:40 UTC, Jean-Yves Lefort
  Details
other fixes (1.34 KB, patch)
2004-09-07 23:04 UTC, Jean-Yves Lefort
none Details | Review
updated fixes (5.23 KB, patch)
2005-03-20 20:16 UTC, Jean-Yves Lefort
none Details | Review
use gotos, and do not lock disconnect emissions (6.85 KB, patch)
2005-07-01 22:23 UTC, Jean-Yves Lefort
committed Details | Review

Description Jean-Yves Lefort 2004-09-06 23:02:26 UTC
The process_ice_messages() callback does not hold the GDK global lock, causing
some multi-threaded GNOME applications to randomly crash at startup.

I highly recommend to apply the patch before GNOME 2.8.
Comment 1 Jean-Yves Lefort 2004-09-06 23:03:03 UTC
Created attachment 31345 [details] [review]
fix
Comment 2 Kjartan Maraas 2004-09-07 17:53:16 UTC
If this is as serious as it sounds it defitely sounds like it should go in. Mark?
Comment 3 Anders Carlsson 2004-09-07 21:27:19 UTC
(Adding Mark to the cc list)

I've never seen any problems with this, I'd say we could delay it to 2.8.1.
Comment 4 Jean-Yves Lefort 2004-09-07 22:39:20 UTC
Created attachment 31395 [details]
demonstrates the bug

I suggest you examine this demonstration, which illustrates a simple scheme
where a program updates its splash screen from a thread.
Comment 5 Jean-Yves Lefort 2004-09-07 22:40:16 UTC
Created attachment 31396 [details]
backtrace

When running against an unpatched libgnomeui it crashes about 25% of the time,
always with a trace similar to this one.
Comment 6 Jean-Yves Lefort 2004-09-07 22:42:29 UTC
Fortunately no mainstream GNOME program seem to be triggering this bug at the
moment, but it is nevertheless serious. Please commit the trivial fix in GNOME 2.8.
Comment 7 Jean-Yves Lefort 2004-09-07 23:04:35 UTC
Created attachment 31397 [details] [review]
other fixes

While I was on this I thought to audit libgnomeui for other bugs of the same
class, and I found three of these, fixed by this patch.

I suggest you perform this audit for all the GNOME libraries being at or above
the GDK layer.
Comment 8 Elijah Newren 2004-09-12 23:48:11 UTC
Punting to 2.8.x
Comment 9 Mark McLoughlin 2004-09-22 12:30:53 UTC
Comment on attachment 31345 [details] [review]
fix

It would seem more correct to me to only take the GDK lock when we need to.

So, the GDK_THREADS_ENTER()/LEAVE() pair would seem to make more sense to me in
client_save_yourself_callback()
Comment 10 Christian Krause 2004-10-25 19:02:11 UTC
Hi,

I can reproduce the problem using the submitted demonstration program. I also
get similar backtraces when using mail-notification (that's why I tested it).

I found one prerequisite for this bug: It only occurs when having Acessibility
enabled. ("Applications/Desktop Preferences/Accessibility/Assistive Technology
Support/Enable assistive technologies").

I hope that helps to determine the problem. I suggest to set this bug to NEW.

Best regards,
Christian
Comment 11 Jean-Yves Lefort 2004-10-30 10:01:19 UTC
Ping
Comment 12 Kjartan Maraas 2005-02-09 23:01:16 UTC
Marking down since this doesn't seem to manifest itself much with regular use. 
Comment 13 Jean-Yves Lefort 2005-02-09 23:08:36 UTC
What about just applying the f*****g patches, now?
Comment 14 Fernando Herrera 2005-03-20 18:45:09 UTC
Please, read mark comments and try to post a new patch. Thanks
Comment 15 Jean-Yves Lefort 2005-03-20 19:28:02 UTC
The g_signal_emit (context, disconnect_id, 0) call should also be protected.
Moreover, I am not sure that client_save_yourself_callback() can only be called
 from process_ice_messages().
Comment 16 Jean-Yves Lefort 2005-03-20 20:16:13 UTC
Created attachment 38976 [details] [review]
updated fixes

Updated patch for libgnomeui 2.10.0, now also protects GConf callbacks.
Comment 17 Jeffrey Stedfast 2005-07-01 17:54:58 UTC
the patch seems to be pretty dubious to me. if you're going to try and make
gnome thread-safe, then you should start at the bottom, not add
gdk_threads_enter/leave around every call. that's just rediculous and totally
the wrong approach to solving your problem.
Comment 18 Jean-Yves Lefort 2005-07-01 18:07:01 UTC
You don't understand the patch.
Comment 19 Kjartan Maraas 2005-07-01 18:31:26 UTC
Well, could you please enlighten people as to what you're trying to achieve
instead of just adding locking pairs and pointing to a crash in a test program
that is almost impossible to trigger? I can't trigger the crash at all here.
Also, telling other developers "You don't understand the patch" without offering
to explain what they supposedly don't understand isn't the best way of getting
attention to your problem.
Comment 20 Kjartan Maraas 2005-07-01 18:33:28 UTC
And btw, from the impression I've gotten after talking to people about this it
seems that this patch for README in libgnomeui is just as pertinent:

diff -u -p -r1.2 README
--- README      18 May 2003 22:10:59 -0000      1.2
+++ README      1 Jul 2005 18:33:09 -0000
@@ -1 +1,4 @@
 This is the gui parts of what was previously gnome-libs
+
+This library is not thread safe.
+
Comment 21 Jean-Yves Lefort 2005-07-01 20:19:36 UTC
GDK is not thread-safe. In multi-threaded applications, the GDK global lock must
be held while using GDK/GTK+ interfaces. Such applications achieve this by
wrapping the GTK+ main loop (gtk_main()) into a GDK_THREADS_ENTER/LEAVE pair.
However, idles, timeouts and input functions are executed with the GDK lock
_not_  held. This is the reason why, when calling GDK/GTK+ from
idle/timeout/input callbacks, you _must_ acquire the GDK global lock (see
http://developer.gnome.org/doc/API/2.0/gdk/gdk-Threads.html). If you look at the
libgnomeui code, you will see that this is already done in some places. My patch
simply holds the GDK global lock where doing so has been forgotten by the
libgnomeui developers.
Comment 22 Matthias Clasen 2005-07-01 20:43:03 UTC
Most of the added enter-leave pairs make sense to me, though I would probably 
convert multiple returns into a goto done, rather than adding multiple leaves.

I have to agree with markmc though, that you can not simply wrap the whole
body of process_ice_messages in an enter-leave pair. That changes the api for
all uses of the disconnect signal. Previously it was emitted without holding the
gdk lock, now it is emitted while holding the lock.
Comment 23 Kjartan Maraas 2005-07-01 20:59:32 UTC
Thank you so much for your input Matthias. Maybe we could massage the patch into
submittable form then so we can get this one resolved finally.

So these are the only issues left to solve:

- changing the multiple returns to use goto's
- move the locking pair from process_ice_messages() into
client_save_yourself_callback()

right?
Comment 24 Jean-Yves Lefort 2005-07-01 22:23:03 UTC
Created attachment 48527 [details] [review]
use gotos, and do not lock disconnect emissions

"Previously it was emitted without holding the gdk lock" -> you forget
gnome_client_disconnect(). Anyway, I have updated the patch.
Comment 25 Luis Villa 2005-07-10 15:02:58 UTC
[Removing the meaninglessly old milestone. If people think this should be a
showstopper for 2.12, feel free to add that.]
Comment 26 Luis Villa 2005-08-24 20:08:32 UTC
<sigh> Can someone review and/or commit this thing? please? :) [Probably on a
2.13 branch? :/
Comment 27 Olav Vitters 2005-12-29 16:44:47 UTC
*** Bug 301754 has been marked as a duplicate of this bug. ***
Comment 28 Christian Krause 2005-12-30 20:53:31 UTC
(In reply to comment #26)
> <sigh> Can someone review and/or commit this thing? please? :) [Probably on a
> 2.13 branch? :/

I have the patches "fix" and "other fixes" applied since gnome-2.8 and I've never seen the problems anymore. Sorry, that I can't say anything about the current patch, but the old ones fixed the problem anyway.
Comment 29 Kjartan Maraas 2006-01-01 22:41:44 UTC
I'm going to commit this to HEAD now. The gtkfilesystemgnomevfs.c patch is rejected now, has this been fixed in a different manner there?
Comment 30 Kjartan Maraas 2006-02-28 22:01:05 UTC
Commited except for the bits in gtkfilesystemgnomevfs.c. Please file a new bug for that if it's still relevant.