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 510547 - Epiphany/Webkit fails to start due to initializing threads twice
Epiphany/Webkit fails to start due to initializing threads twice
Status: RESOLVED NOTGNOME
Product: epiphany
Classification: Core
Component: General
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Epiphany Maintainers
Epiphany Maintainers
Depends on:
Blocks:
 
 
Reported: 2008-01-19 04:53 UTC by Jonathon Jongsma
Modified: 2008-01-20 12:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Check whether threads are initialized before calling g_thread_init() (449 bytes, patch)
2008-01-19 04:58 UTC, Jonathon Jongsma
none Details | Review

Description Jonathon Jongsma 2008-01-19 04:53:30 UTC
I built epiphany/webkit for the first time via jhbuild, but it wouldn't start and gave this error on the commandline:

GThread-ERROR **: GThread system may only be initialized once.

It appears that g_thread_init() is being called in a WebKit global constructor somewhere, which happens before main().  So when Epiphany initializes threads, it aborts.
Comment 1 Jonathon Jongsma 2008-01-19 04:58:33 UTC
Created attachment 103184 [details] [review]
Check whether threads are initialized before calling g_thread_init()

I'm not sure if this is necessarily the correct fix, but it seems to fix things for me.
Comment 2 Xan Lopez 2008-01-19 12:01:49 UTC
(In reply to comment #0)
> I built epiphany/webkit for the first time via jhbuild, but it wouldn't start
> and gave this error on the commandline:
> 
> GThread-ERROR **: GThread system may only be initialized once.
> 
> It appears that g_thread_init() is being called in a WebKit global constructor
> somewhere, which happens before main().  So when Epiphany initializes threads,
> it aborts.
> 

I don't think it's possible that the webkit constructor is called befare our main :)

Are you sure it comes from ephy-main? Could you break on g_log and see who's calling it?
Comment 3 Xan Lopez 2008-01-19 12:03:06 UTC
FWIW, WebKit checks before initializing threads. Odd.
Comment 4 Jonathon Jongsma 2008-01-19 15:05:27 UTC
Oh, in c++ it's quite possible for a constructor to run before main if it's a global object.

Here is the backtrace from g_log:
Breakpoint 2, IA__g_log (log_domain=0xb61e6868 "GThread", log_level=G_LOG_LEVEL_ERROR, 
    format=0xb61e6ee4 "GThread system may only be initialized once.") at gmessages.c:516
516       va_start (args, format);
(gdb) bt
  • #0 IA__g_log
    at gmessages.c line 516
  • #1 g_thread_init
    at gthread-impl.c line 297
  • #2 main
    at ephy-main.c line 442
  • #0 g_thread_init
    at gthread-impl.c line 293
  • #1 _gst_plugin_register_static
    at gstplugin.c line 175
  • #2 _gst_plugin_static_init__plugin_init
    from /opt/gnome2/lib/libWebKitGtk.so.1
  • #3 __do_global_ctors_aux
    from /opt/gnome2/lib/libWebKitGtk.so.1
  • #4 _init
    from /opt/gnome2/lib/libWebKitGtk.so.1
  • #5 call_init
    from /lib/ld-linuxBreakpoint
  • #0 g_thread_init
    at gthread-impl.c line 293
  • #1 _gst_plugin_register_static
    at gstplugin.c line 175
  • #2 _gst_plugin_static_init__plugin_init
    from /opt/gnome2/lib/libWebKitGtk.so.1
  • #3 __do_global_ctors_aux
    from /opt/gnome2/lib/libWebKitGtk.so.1
  • #4 _init
    from /opt/gnome2/lib/libWebKitGtk.so.1
  • #5 call_init
    from /lib/ld-linux.so.2
  • #6 _dl_init_internal
    from /lib/ld-linux.so.2
  • #7 _dl_start_user
    from /lib/ld-linux.so.2
  • #6 _dl_init_internal
    from /lib/ld-linux.so.2
  • #7 _dl_start_user
    from /lib/ld-linux.so.2

I built webkit with --enable-video, so it looks like WebKit is initializing some gstreamer stuff in a global constructor which also initializes threads.  

Hope that helps
Comment 5 Xan Lopez 2008-01-19 15:09:16 UTC
Madness! :)

Ok, then we should definitely guard the thread initialization in our main (it's probably a good idea *anyway*).

chpe?
Comment 6 Christian Persch 2008-01-19 15:37:20 UTC
I think webkit shouldn't have global constructors. Where is that code in webkit, exactly?
Comment 7 Jonathon Jongsma 2008-01-19 16:28:16 UTC
Well, I would agree that it's slightly questionable for webkit to be initializing it in a global constructor, which is why I said I wasn't sure if it was the right fix or not.  I took a quick look through the webkit source to try to find out where it's happening, but I'm not familiar with webkit code, and I couldn't spot it immediately.
Even so, my patch doesn't seem like it would do any harm in any case.  It would make things a bit more robust, but I suppose it would hide issues like this (I don't know whether you'd consider that a good thing or not).
Comment 8 Jonathon Jongsma 2008-01-19 16:31:23 UTC
Also, just to avoid confusion: if you didn't notice, my backtrace above is oddly corrupted.  It appears that I copy/pasted the stack track twice and the second time I pasted it into the middle of the first one.  The correct trace is:

(init=0x0) at gthread-impl.c:293
293     {
(gdb) bt
  • #0 g_thread_init
    at gthread-impl.c line 293
  • #1 _gst_plugin_register_static
    at gstplugin.c line 175
  • #2 _gst_plugin_static_init__plugin_init
    from /opt/gnome2/lib/libWebKitGtk.so.1
  • #3 __do_global_ctors_aux
    from /opt/gnome2/lib/libWebKitGtk.so.1
  • #4 _init
    from /opt/gnome2/lib/libWebKitGtk.so.1
  • #5 call_init
    from /lib/ld-linux.so.2
  • #6 _dl_init_internal
    from /lib/ld-linux.so.2
  • #7 _dl_start_user
    from /lib/ld-linux.so.2

Comment 9 Mark Rowe 2008-01-20 03:51:41 UTC
It's happening due to the use of GST_PLUGIN_DEFINE_STATIC in VideoSinkGStreamer.cpp.  This GStreamer macro expands out to generating a constructor function that calls into _gst_plugin_register_static, which somehow results in g_thread_init being called.  We should be able to fix this in WebKit by not using the GST_PLUGIN_DEFINE_STATIC macro, and instead deferring the operation until first use.
Comment 10 Mark Rowe 2008-01-20 04:06:48 UTC
Filed in WebKit's Bugzilla as <http://bugs.webkit.org/show_bug.cgi?id=16944>.
Comment 11 alp 2008-01-20 04:30:46 UTC
This appears to have been caused by a recent change in GStreamer. Since static initializers are bad anyway, I'm working on a fix in WebKit.

http://bugs.webkit.org/show_bug.cgi?id=16944
Comment 12 alp 2008-01-20 04:55:56 UTC
Fix landed in WebKit r29675/r29676.
Comment 13 Xan Lopez 2008-01-20 12:41:45 UTC
Thanks guys. I guess we can close this now, as chpe does not want to add the check in our main.