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 646246 - dbus: Add connect_sync() method to bus objects
dbus: Add connect_sync() method to bus objects
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
: 646177 (view as bug list)
Depends on:
Blocks: 646177
 
 
Reported: 2011-03-30 16:14 UTC by Colin Walters
Modified: 2011-04-05 22:13 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
dbus: Add connect_sync() method to bus objects (2.09 KB, patch)
2011-03-30 16:14 UTC, Colin Walters
none Details | Review
dbus: Allow synchronous connections (4.47 KB, patch)
2011-03-30 20:20 UTC, Colin Walters
needs-work Details | Review
dbus: Do connection processing in a high priority timeout (1.74 KB, patch)
2011-04-01 19:20 UTC, Colin Walters
reviewed Details | Review

Description Colin Walters 2011-03-30 16:14:54 UTC
This is useful for ensuring we're connected; the
default of processing in an idle can create race
conditions.
Comment 1 Colin Walters 2011-03-30 16:14:56 UTC
Created attachment 184708 [details] [review]
dbus: Add connect_sync() method to bus objects
Comment 2 Colin Walters 2011-03-30 20:20:34 UTC
Created attachment 184731 [details] [review]
dbus: Allow synchronous connections

In gnome-shell, we added a call to DBus.session.flush() to attempt to
ensure we were connected immediately.  But this has multiple problems,
and actually it never quite worked because gjs-dbus had a hidden
"process in idle".

Add a connect_sync() function, and make it really synchronous.
Comment 3 Owen Taylor 2011-04-01 18:32:50 UTC
Review of attachment 184731 [details] [review]:

Hmm, I think there is a problem here - presumably the reason it's done in an idle now is to avoid reentrancy, but by making check_bus() force the connections, you've created a more sever reentrancy - if you try to acquire a name, then the next outgoing call can cause name ownership monitors and watchers to fire, which is pretty unexpected.

I'd suggest that there probably needs to be a separate gjs-dbus method which basically does:

if (<blah>connect_idle) {
   unset <blah>connect-idle;
    connect_idle(...);
}

Rather than wedging it into gjs_dbus_try_connecting_now() - I'd also suggest that the gjs exported method name should be something other than connect_sync() since it makes sense at any time you need to acquire a name now - connect_idle (perhaps oddly) can be set up an run for an existing connection when we acquire a new name.
Comment 4 Colin Walters 2011-04-01 19:20:40 UTC
Created attachment 184888 [details] [review]
dbus: Do connection processing in a high priority timeout

Otherwise, we risk race conditions if dbus-glib processes
messages before we've had a chance to set up our exports.
Comment 5 Colin Walters 2011-04-01 19:28:39 UTC
<owen> OK, I think this patch is problmatical
 it means that any outgoing call can cause reentrancy to your name ownership monitors
 I'll comment on the bug
<walters> owen: so i agree you're right in theory, but in practice, with this patch, we connect to the session bus before we set up monitors
...
<walters> owen: no the problem is simply that exports are set up in an idle, which is lower priority than reading from the dbus socket
 so that's why we see this nearly 100% of the time
...
<owen> Hmm, OK, so I think it's basically broken if I call dbus.exportObject and it doesn't take effect immediatley for subsequent incoming calls once I return to the main loop, so I can't see that we should require any changes to gnome-shell - this seems like something we should fix in gjs
Comment 6 Owen Taylor 2011-04-01 19:43:19 UTC
Review of attachment 184888 [details] [review]:

Good except for comment

::: gjs-dbus/dbus.c
@@ +353,3 @@
+             * potentially reading any messages from the socket.  If we
+             * didn't, this could lead to race conditions.  See
+             * https://bugzilla.gnome.org/show_bug.cgi?id=646246

This comment is confusing, since this code is completely generic and the export handling is added in a different layer. I'd say:

 "so that deferred work, such as the
  gjs_dbus_add_connect_funcs() callbacks that are used
  to set up exports by the DBus JS module runs *before*..."
Comment 7 Dan Winship 2011-04-04 00:40:26 UTC
Comment on attachment 184888 [details] [review]
dbus: Do connection processing in a high priority timeout

I'm not very familiar with gjs-dbus, but this seems right.

You don't actually need to switch from an idle to a 0-timeout btw. An "idle" with G_PRIORITY_HIGH is just as high-priority as a timeout with G_PRIORITY_HIGH.
Comment 8 Owen Taylor 2011-04-04 01:47:02 UTC
*** Bug 646177 has been marked as a duplicate of this bug. ***
Comment 9 Owen Taylor 2011-04-05 22:13:50 UTC
Pushed with r-t approval and released in 0.7.14