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 767299 - Adding a Telepathy account is racy after adding a headerbar
Adding a Telepathy account is racy after adding a headerbar
Status: RESOLVED FIXED
Product: gnome-online-accounts
Classification: Core
Component: Telepathy
3.21.x
Other All
: Normal normal
: ---
Assigned To: GNOME Online Accounts maintainer(s)
GNOME Online Accounts maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2016-06-06 16:41 UTC by Debarshi Ray
Modified: 2017-04-08 19:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
telepathy: Simplify the code by re-using the existing GoaClient (2.56 KB, patch)
2016-06-06 17:11 UTC, Debarshi Ray
committed Details | Review
telepathy: Remove the unused GCancellable (1.62 KB, patch)
2016-06-06 17:11 UTC, Debarshi Ray
committed Details | Review
telepathy: Make the GoaObject code resemble its TpAccount counterpart (4.18 KB, patch)
2016-06-06 17:12 UTC, Debarshi Ray
rejected Details | Review
telepathy: Fix a race between TpawAccountWidget and GoaTpAccountLinker (3.30 KB, patch)
2016-06-06 17:12 UTC, Debarshi Ray
committed Details | Review
telepathy: Fix a race between TpawAccountWidget and GoaTpAccountLinker (3.34 KB, patch)
2016-06-07 15:46 UTC, Debarshi Ray
committed Details | Review

Description Debarshi Ray 2016-06-06 16:41:13 UTC
Ever since we changed the dialog to use a header bar (bug 729638), adding a Telepathy account became racy.

The code looks like this:
  * create TpawAccoutWidget inside a GtkDialog
  * wait for gtk_dialog_run to return
  * if the GoaObject is not yet available, run a GMainLoop to wait for it

The original pre-headerbar code assumed that TpawAccountWidget::close will be emitted once the account has been created and ready to use. The TpawAccountWidget::close handler in turn emitted GtkDialog::response.  It then used a hand rolled GMainLoop to wait for GoaTpAccountLinker to create the corresponding GoaObject.

Note that TpawAccountWidget doesn't just create the TpAccount. It does some more asynchronous work with it. eg., enabling it. On the other hand, GoaTpAccountLinker starts creating the GoaObject immediately when the TpAccount is created. Therefore, there is no guarantee that 
TpawAccountWidget::close will be emitted before GoaTpAccountLinker has created the corresponding GoaObject.

Now, post-headerbar, GtkDialog::response is emitted immediately when the user clicks one of the response buttons, and we return from gtk_dialog_run. At this point the TpAccount hasn't even been created. Once it is ready, TpawAccountWidget::close (and a second GtkDialog::response) would follow, but there is nothing to match it. We are relying on TpawAccountWidget::close to win the race against GoaTpAccountLinker. If it loses the race, then the GMainLoop will be quit while the dialog is still working, and lead to a memory error.

Surprisingly, at least on my system, we were winning the race all the time, until recently. eg., one git bisect run pointed at commit 3dfcd3c4df589db2 as the faulty commit, which doesn't make sense.
Comment 1 Debarshi Ray 2016-06-06 17:11:11 UTC
Created attachment 329211 [details] [review]
telepathy: Simplify the code by re-using the existing GoaClient
Comment 2 Debarshi Ray 2016-06-06 17:11:39 UTC
Created attachment 329212 [details] [review]
telepathy: Remove the unused GCancellable
Comment 3 Debarshi Ray 2016-06-06 17:12:09 UTC
Created attachment 329213 [details] [review]
telepathy: Make the GoaObject code resemble its TpAccount counterpart
Comment 4 Debarshi Ray 2016-06-06 17:12:43 UTC
Created attachment 329214 [details] [review]
telepathy: Fix a race between TpawAccountWidget and GoaTpAccountLinker
Comment 5 Debarshi Ray 2016-06-06 17:13:30 UTC
Related: bug 767295
Comment 6 Debarshi Ray 2016-06-07 15:18:58 UTC
Review of attachment 329213 [details] [review]:

I don't like this change anymore because:

::: src/goabackend/goatelepathyprovider.c
@@ +347,3 @@
+
+  g_assert (data->goa_object == NULL);
+  data->goa_object = g_object_ref (goa_object);

We can't be sure that nobody is adding a Telepathy account behind our back. If that happens, then we can't assert that data->goa_object is NULL.
Comment 7 Debarshi Ray 2016-06-07 15:44:52 UTC
Review of attachment 329213 [details] [review]:

Let's drop this.
Comment 8 Debarshi Ray 2016-06-07 15:46:41 UTC
Created attachment 329294 [details] [review]
telepathy: Fix a race between TpawAccountWidget and GoaTpAccountLinker
Comment 9 Debarshi Ray 2016-06-10 14:27:35 UTC
(In reply to Debarshi Ray from comment #0)
> Surprisingly, at least on my system, we were winning the race all the time,
> until recently. eg., one git bisect run pointed at commit 3dfcd3c4df589db2
> as the faulty commit, which doesn't make sense.

The Telepathy provider used to store empty keyring entries. It could be that the change to not do that (ie. commit 3dfcd3c4df589db2) changed the outcome of the race.