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 627724 - gtester hangs on startup
gtester hangs on startup
Status: RESOLVED DUPLICATE of bug 674885
Product: glib
Classification: Platform
Component: gobject
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
: 628889 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2010-08-23 13:27 UTC by Xan Lopez
Modified: 2017-03-15 12:37 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Xan Lopez 2010-08-23 13:27:19 UTC
With latest master of glib/dconf (not sure if it's relevant, but it appears on the trace), gtester hangs on startup and spins using 100% CPU forever. Trace:

(gdb) bt
  • #0 __kernel_vsyscall
  • #1 sched_yield
    at ../sysdeps/unix/syscall-template.S line 82
  • #2 g_thread_yield_posix_impl
    at gthread-posix.c line 378
  • #3 _g_dbus_shared_thread_ref
    at gdbusprivate.c line 317
  • #4 _g_dbus_worker_new
    at gdbusprivate.c line 1362
  • #5 initable_init
    at gdbusconnection.c line 2223
  • #6 g_initable_init
    at ginitable.c line 105
  • #7 g_bus_get_sync
    at gdbusconnection.c line 6091
  • #8 dconf_settings_backend_get_bus
    at dconfsettingsbackend.c line 380
  • #9 dconf_settings_backend_subscribe
    at dconfsettingsbackend.c line 512
  • #10 g_settings_backend_subscribe
    at gsettingsbackend.c line 905
  • #11 g_settings_constructed
    at gsettings.c line 468
  • #12 g_object_newv
    at gobject.c line 1375
  • #13 g_object_new_valist
    at gobject.c line 1463
  • #14 g_object_new
    at gobject.c line 1181
  • #15 g_settings_new
    at gsettings.c line 697
  • #16 inspectorGSettings
    from /home/xan/git/webkit/build/normal/.libs/libwebkitgtk-3.0.so.0
  • #17 webkit_init
    from /home/xan/git/webkit/build/normal/.libs/libwebkitgtk-3.0.so.0
  • #18 webkit_web_view_class_intern_init(void*)
    from /home/xan/git/webkit/build/normal/.libs/libwebkitgtk-3.0.so.0
  • #19 type_class_init_Wm
    at gtype.c line 2214
  • #20 g_type_class_ref
    at gtype.c line 2913
  • #21 g_object_newv
    at gobject.c line 1252
  • #22 g_object_new
    at gobject.c line 1178
  • #23 webkit_web_view_new
    from /home/xan/git/webkit/build/normal/.libs/libwebkitgtk-3.0.so.0
  • #24 dom_document_fixture_setup
    at ../../WebKit/gtk/tests/testdomdocument.c line 51
  • #25 test_case_run
    at gtestutils.c line 1173
  • #26 g_test_run_suite_internal
    at gtestutils.c line 1223
  • #27 g_test_run_suite_internal
    at gtestutils.c line 1233
  • #28 g_test_run_suite_internal
    at gtestutils.c line 1233
  • #29 g_test_run_suite
    at gtestutils.c line 1274
  • #30 g_test_run
    at gtestutils.c line 877
  • #31 main
    at ../../WebKit/gtk/tests/testdomdocument.c line 222

Ryan suggested a call to g_bus_get_sync at the very beginning of the test program. This indeed seems to workaround the issue.
Comment 1 David Zeuthen (not reading bugmail) 2010-08-23 15:49:00 UTC
I need stack traces for all threads (t a a bt)
Comment 2 Carlos Garcia Campos 2010-08-23 15:57:08 UTC
I have the same problem when trying to run ephy with current webkit. 

(gdb) thread apply all bt

Hilo 3 (Thread 0xb4e47b70 (LWP 11015)):
  • #0 __kernel_vsyscall
  • #1 pthread_cond_wait
    at ../nptl/sysdeps/unix/sysv/linux/i386/i686/../i486/pthread_cond_wait.S line 122
  • #2 WTF::TCMalloc_PageHeap::scavengerThread()
    from /home/carlos/gnome-cvs/lib/libwebkitgtk-3.0.so.0
  • #3 WTF::TCMalloc_PageHeap::runScavengerThread(void*)
    from /home/carlos/gnome-cvs/lib/libwebkitgtk-3.0.so.0
  • #4 start_thread
    at pthread_create.c line 300
  • #5 clone
    at ../sysdeps/unix/sysv/linux/i386/clone.S line 130
  • #0 __kernel_vsyscall
  • #1 __lll_lock_wait
    at ../nptl/sysdeps/unix/sysv/linux/i386/i686/../i486/lowlevellock.S line 142
  • #2 _L_lock_748
    from /lib/tls/i686/cmov/libpthread.so.0
  • #3 __pthread_mutex_lock
    at pthread_mutex_lock.c line 61
  • #4 g_static_rec_mutex_lock
    at gthread.c line 1424
  • #5 g_type_add_interface_static
    at gtype.c line 2809
  • #6 g_simple_async_result_get_type
    at gsimpleasyncresult.c line 247
  • #7 g_simple_async_result_new
    at gsimpleasyncresult.c line 321
  • #8 _g_socket_read_with_control_messages
    at gdbusprivate.c line 188
  • #9 _g_dbus_worker_do_read_unlocked
    at gdbusprivate.c line 797
  • #10 _g_dbus_worker_do_read
    at gdbusprivate.c line 814
  • #11 _g_dbus_worker_thread_begin_func
    at gdbusprivate.c line 1320
  • #12 invoke_caller
    at gdbusprivate.c line 266
  • #13 g_idle_dispatch
    at gmain.c line 4224
  • #14 g_main_dispatch
    at gmain.c line 2119
  • #15 g_main_context_dispatch
    at gmain.c line 2672
  • #16 g_main_context_iterate
    at gmain.c line 2750
  • #17 g_main_loop_run
    at gmain.c line 2958
  • #18 shared_thread_func
    at gdbusprivate.c line 248
  • #19 g_thread_create_proxy
    at gthread.c line 1897
  • #20 start_thread
    at pthread_create.c line 300
  • #21 clone
    at ../sysdeps/unix/sysv/linux/i386/clone.S line 130
  • #0 __kernel_vsyscall
  • #1 sched_yield
    at ../sysdeps/unix/syscall-template.S line 82
  • #2 g_thread_yield_posix_impl
    at gthread-posix.c line 378
  • #3 _g_dbus_shared_thread_ref
    at gdbusprivate.c line 317
  • #4 _g_dbus_worker_new
    at gdbusprivate.c line 1360
  • #5 initable_init
    at gdbusconnection.c line 2223
  • #6 g_initable_init
    at ginitable.c line 105
  • #7 g_bus_get_sync
    at gdbusconnection.c line 6091
  • #8 dconf_settings_backend_get_bus
    at dconfsettingsbackend.c line 380
  • #9 dconf_settings_backend_subscribe
    at dconfsettingsbackend.c line 512
  • #10 g_settings_backend_subscribe
    at gsettingsbackend.c line 905
  • #11 g_settings_constructed
    at gsettings.c line 468
  • #12 g_object_newv
    at gobject.c line 1375
  • #13 g_object_new_valist
    at gobject.c line 1463
  • #14 g_object_new
    at gobject.c line 1181
  • #15 g_settings_new
    at gsettings.c line 697
  • #16 inspectorGSettings
    from /home/carlos/gnome-cvs/lib/libwebkitgtk-3.0.so.0
  • #17 webkit_init
    from /home/carlos/gnome-cvs/lib/libwebkitgtk-3.0.so.0
  • #18 webkit_web_settings_class_intern_init(void*)
    from /home/carlos/gnome-cvs/lib/libwebkitgtk-3.0.so.0
  • #19 type_class_init_Wm
    at gtype.c line 2214
  • #20 g_type_class_ref
    at gtype.c line 2913
  • #21 g_object_newv
    at gobject.c line 1252
  • #22 g_object_new
    at gobject.c line 1178
  • #23 webkit_web_settings_new
    from /home/carlos/gnome-cvs/lib/libwebkitgtk-3.0.so.0
  • #24 ephy_embed_prefs_init
    at ephy-embed-prefs.c line 498
  • #25 ephy_embed_single_initialize
    at ephy-embed-single.c line 461
  • #26 impl_get_embed_single
    at ephy-embed-shell.c line 250
  • #27 impl_get_embed_single
    at ephy-shell.c line 180
  • #28 ephy_embed_shell_get_embed_single
    at ephy-embed-shell.c line 282
  • #29 ephy_window_constructor
    at ephy-window.c line 3552
  • #30 g_object_newv
    at gobject.c line 1347
  • #31 g_object_new_valist
    at gobject.c line 1463
  • #32 g_object_new
    at gobject.c line 1181
  • #33 ephy_window_new_with_chrome
    at ephy-window.c line 3632
  • #34 ephy_shell_new_tab_full
    at ephy-shell.c line 385
  • #35 session_command_dispatch
    at ephy-session.c line 726
  • #36 g_idle_dispatch
    at gmain.c line 4224
  • #37 g_main_dispatch
    at gmain.c line 2119
  • #38 g_main_context_dispatch
    at gmain.c line 2672
  • #39 g_main_context_iterate
    at gmain.c line 2750
  • #40 g_main_loop_run
    at gmain.c line 2958
  • #41 gtk_main
    at gtkmain.c line 1203
  • #42 main
    at ephy-main.c line 739

Comment 3 Xan Lopez 2010-08-23 16:00:00 UTC
Yeah, similar thing.



Comment 4 David Zeuthen (not reading bugmail) 2010-08-23 16:01:38 UTC
Looks like a problem with GType holding a lock while calling the init() function for a GObject-derived type... reassigning to gobject.
Comment 5 David Zeuthen (not reading bugmail) 2010-08-23 16:12:58 UTC
Actually looks like it is because of code in the GClassInitFunc, not the instance initializer (e.g. "static void my_type_init(MyType *instance)" function).

Maybe the answer is simply "don't create object instances in GClassInitFunc functions".

A workaround for WebKit could be to move the instance-creating code elsewhere, maybe the instance initializer.
Comment 6 Xan Lopez 2010-08-23 16:28:46 UTC
(In reply to comment #5)
> Actually looks like it is because of code in the GClassInitFunc, not the
> instance initializer (e.g. "static void my_type_init(MyType *instance)"
> function).
> 
> Maybe the answer is simply "don't create object instances in GClassInitFunc
> functions".
> 
> A workaround for WebKit could be to move the instance-creating code elsewhere,
> maybe the instance initializer.

Right. This is actually a fairly recent thing, we call an init function for WebKit on demand in all class_init functions (an ill-conceived idea IMHO, but it was done a long time ago), and we just added some gsettings stuff there that calls g_settings_new(), I guess that's where the problem is coming from. I suppose we can start looking into moving it somewhere else, but I wouldn't be surprised if this hits more people in the future to be honest.
Comment 7 Matthias Clasen 2010-08-26 00:24:42 UTC
A little hard to write this down clearly in the docs:

In a class init function, don't do anything that causes other threads to initialize classed types. 

?
Comment 8 David Zeuthen (not reading bugmail) 2010-08-26 00:36:41 UTC
(In reply to comment #7)
> A little hard to write this down clearly in the docs:
> 
> In a class init function, don't do anything that causes other threads to
> initialize classed types. 
> 
> ?

Actually threading doesn't matter does it? Calling any function that results in type registration will cause a deadlock, no?
Comment 9 Matthias Clasen 2010-08-26 02:13:53 UTC
its a recursive lock, so I believe we would be fine if this happened in the same thread.
Comment 10 David Zeuthen (not reading bugmail) 2010-09-06 14:57:27 UTC
*** Bug 628889 has been marked as a duplicate of this bug. ***
Comment 11 David Zeuthen (not reading bugmail) 2010-09-06 15:02:57 UTC
Maybe, as a workaround, gdbus could do things like

 static volatile GType _g_volatile_type;

 _g_volatile_type = G_SIMPLE_ASYNC_RESULT_TYPE;
 _g_volatile_type = G_ASYNC_RESULT_TYPE
 [...]

before launching the helper thread. Would need to do it for all types we know the helper thread needs for initialization (not a lot I guess).

(The real fix, of course, is to fix gobject so it doesn't hold any locks while calling out to user code. But that seems a lot more complicated.)
Comment 12 David Zeuthen (not reading bugmail) 2010-09-10 20:24:16 UTC
(In reply to comment #11)
> Maybe, as a workaround, gdbus could do things like
> 
>  static volatile GType _g_volatile_type;
> 
>  _g_volatile_type = G_SIMPLE_ASYNC_RESULT_TYPE;
>  _g_volatile_type = G_ASYNC_RESULT_TYPE
>  [...]
> 
> before launching the helper thread. Would need to do it for all types we know
> the helper thread needs for initialization (not a lot I guess).
> 
> (The real fix, of course, is to fix gobject so it doesn't hold any locks while
> calling out to user code. But that seems a lot more complicated.)

I've now done this, see

 http://git.gnome.org/browse/glib/commit/?id=0b74058fa3144f85b5fefd4c81129b971010452a
Comment 13 Thomas M. 2011-09-29 07:55:33 UTC
Bug 660423 might be a duplicate of this bug, it has a similar backtrace, and was observed with glib 2.28.6 which has the code supposed to work around this bug.
Comment 14 Dan Winship 2012-02-25 19:16:23 UTC
*** Bug 670479 has been marked as a duplicate of this bug. ***
Comment 15 Dan Winship 2012-02-25 19:46:10 UTC
Hm. actually, no. This is a different bug.

And I don't think this can be called gobject's fault; it was caused by the fact that _g_dbus_worker_new() used to block waiting for the worker thread to be fully set up, and the worker thread registered some types during setup, but the _g_dbus_worker_new() thread was already holding the gtype locks.

So this should have been fixed by Colin's patch for bug 651650 (which made _g_dbus_worker_new() no longer block), and so it should be safe to remove the ensure_required_types() hack at this point.
Comment 16 Colin Walters 2016-10-13 14:43:34 UTC
See https://bugzilla.gnome.org/show_bug.cgi?id=674885 which shows the problem extends beyond GDBus.
Comment 17 Bastien Nocera 2017-03-15 12:37:29 UTC

*** This bug has been marked as a duplicate of bug 674885 ***