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 724060 - Fixes for assertions during context dispose
Fixes for assertions during context dispose
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2014-02-10 18:37 UTC by Colin Walters
Modified: 2014-02-10 22:00 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
object: Correct assertion about toggle up/down on unref (1.85 KB, patch)
2014-02-10 18:37 UTC, Colin Walters
reviewed Details | Review
Further fixes for assertions during context dispose (10.10 KB, patch)
2014-02-10 18:37 UTC, Colin Walters
needs-work Details | Review
Fix assertions during context dispose (11.79 KB, patch)
2014-02-10 20:33 UTC, Colin Walters
committed Details | Review

Description Colin Walters 2014-02-10 18:37:27 UTC
I didn't actually yet write the patch that removes the g_object_unref
on the context in gjs-console, but it is tempting...
Comment 1 Colin Walters 2014-02-10 18:37:28 UTC
Created attachment 268710 [details] [review]
object: Correct assertion about toggle up/down on unref

It's normal and possible for there to be *both* a TOGGLE_UP and a
TOGGLE_DOWN queued.  In that case, they would cancel, and we'd be in a
correct state.

This was consistently triggering in the ostree gjs-based
test-sysroot.js.
Comment 2 Colin Walters 2014-02-10 18:37:32 UTC
Created attachment 268711 [details] [review]
Further fixes for assertions during context dispose

The current toggle ref code has and assertion that we don't have a
DOWN notification pending while the object is supposed to be live -
and during normal operation, this is true.

Except at context shutdown, we force the JS object to be destroyed,
which can cause recursion into a dispose handler of a gobject, which
can then queue a toggle down.  Then we later force dispose that
object, and find the DOWN pending.

Now, the next patch will simply avoid all of this insanity by default
and allow the kernel to clean up our state much faster, in a more
power efficient way by simply not doing any of this shit =)

However, there are valid use cases for wanting "clean" exits, such as
valgrind.  So this patch fixes things up for the dispose by iterating
over the entire live object list before we drop into the JS context
destruction, breaking the JS <-> C association.  This safely clears
the toggle refs, so the JS side is just JS cleanup, we don't reenter
GObject land.

This will make several of the OSTree tests written using gjs start
passing in Continuous again.  \o/
Comment 3 Jasper St. Pierre (not reading bugmail) 2014-02-10 18:53:13 UTC
Review of attachment 268710 [details] [review]:

Can you introduce a test for this in the gjs testsuite? I'm not sure how it would trigger...
Comment 4 Jasper St. Pierre (not reading bugmail) 2014-02-10 18:57:28 UTC
Review of attachment 268711 [details] [review]:

"the next patch"?

I think you also forgot to git add context-private.h. To be honest, I've been putting that sort of stuff in jsapi-util.h, which is where most of it exists already, but if you want to add a context-private.h, go for it. I might move some other stuff over.

::: gi/object.cpp
@@ +1110,3 @@
+     */
+    gjs_keep_alive_iterator_init (&kiter, keep_alive);
+    while (gjs_keep_alive_iterator_next (&kiter, 

trailing whitespace?
Comment 5 Colin Walters 2014-02-10 20:33:43 UTC
Created attachment 268731 [details] [review]
Fix assertions during context dispose

Well, the nice thing about the InstalledTests model is that the other
tests also act as gjs tests...it'd be really quite painful to manually
replicate the chain of objects in gjs.

I don't really need it anyways, since it appears to only happen during
context dispose anyways, so let's just go with the second patch.
Comment 6 Jasper St. Pierre (not reading bugmail) 2014-02-10 20:37:48 UTC
Review of attachment 268731 [details] [review]:

::: gi/keep-alive.cpp
@@ +334,2 @@
 JSObject*
+gjs_keep_alive_get_global_if_exists (JSContext *context)

I know it's annoying, but the gjs style has no spaces between name and ().

::: gi/keep-alive.h
@@ +77,3 @@
+struct GjsKeepAliveIter {
+    gpointer dummy[4];
+    guint v;

What's the motivation for this? We don't have a stable public API to care about.
Comment 7 Colin Walters 2014-02-10 22:00:03 UTC
(In reply to comment #6)

> ::: gi/keep-alive.h
> @@ +77,3 @@
> +struct GjsKeepAliveIter {
> +    gpointer dummy[4];
> +    guint v;
> 
> What's the motivation for this? We don't have a stable public API to care
> about.

Just best practice not to leak implementation details.
Comment 8 Colin Walters 2014-02-10 22:00:26 UTC
Attachment 268731 [details] pushed as be5c12c - Fix assertions during context dispose