Merge lp:~xavi-garcia-mena/indicator-sound/restart-dbus-error into lp:indicator-sound/15.10

Proposed by Xavi Garcia on 2015-11-04
Status: Needs review
Proposed branch: lp:~xavi-garcia-mena/indicator-sound/restart-dbus-error
Merge into: lp:indicator-sound/15.10
Diff against target: 79 lines (+28/-11)
1 file modified
src/main.c (+28/-11)
To merge this branch: bzr merge lp:~xavi-garcia-mena/indicator-sound/restart-dbus-error
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve on 2015-12-09
Lars Karlitski (community) Disapprove on 2015-11-09
Charles Kerr 2015-11-04 Pending
Review via email: mp+276653@code.launchpad.net

Commit message

Added some time before exiting the indicator if we've got an error owning the dbus name. This lets dbus system to fully start

Description of the change

Added some time before exiting the indicator if we've got an error owning the dbus name. This lets dbus system to fully start

To post a comment you must log in.
509. By Xavi Garcia on 2015-11-09

Added a retry mechanism to try to own the dbus name

Lars Karlitski (larsu) wrote :

No. Please don't fix race conditions with sleep().

review: Disapprove
Xavi Garcia (xavi-garcia-mena) wrote :

Thanks for the review, Lars.

I don't like the sleep either, but if the indicator is starting while dbus is not ready yet I guess we can only implement a wait/retry mechanism waiting to be ready or go down to the real root of the problem and see why is this happening. Maybe upstart is starting the indicator too early.

From the indicator point of view I don't see another way of doing this, though.

Lars Karlitski (larsu) wrote :

> I don't like the sleep either, but if the indicator is starting while dbus is
> not ready yet I guess we can only implement a wait/retry mechanism waiting to
> be ready or go down to the real root of the problem and see why is this
> happening. Maybe upstart is starting the indicator too early.

Yes, please find the real cause for this issue. That's probably not easy, but no desktop component can deal with D-Bus not being available, and I don't think patching all of them like this is desirable. There's already too many pitfalls to watch out for when using D-Bus. Let's not add another one.

Do you have a specific bug that you're fixing with patch? If so, please link it from this Merge Proposal.

Xavi Garcia (xavi-garcia-mena) wrote :

sure, bug linked.

510. By Xavi Garcia on 2015-12-09

Modified time to wait

Xavi Garcia (xavi-garcia-mena) wrote :

Although the approach in this branch is not ideal I'm implementing the workaround like this to wait for dbus session connection to be ready.

This might happen to any indicator, but is more easy to recreate for the sound indicator as the very first thing the indicator does is to try to acquire its dbus name.

I've opened a separated bug for this:
https://bugs.launchpad.net/upstart/+bug/1525183 in which the root issue should be fixed.

I've also like to note that the issue will be probably fixed when we move to systemd.
The idea would be to rollback this branch when the switch to systemd is done.

Lars Karlitski (larsu) wrote :

Even if you wanted to merge this, I don't see how this patch fixes any problem.

If the connection is really not there (which I highly doubt, but might be something related to what Pete was saying in the linked bug), indicator-sound should simply exit, because the on_name_lost() callback is called in that case with a NULL connection. I just verified that it does this by unsetting DBUS_SESSION_BUSA_ADRESS. Upstart should automatically respawn the process after some time.

Do you know who sends the SIGTERM to the process?

What's the stack trace of the critical that is pasted in the linked bug (run it with G_DEBUG=fatal-criticals)?

Xavi Garcia (xavi-garcia-mena) wrote :

Hi Lars,

the process exists itself, no other process sends SIGTERM.
It just stops the loop and exists.

I saw upstart tries to respawn, but only 3 times. After 3 times the result is a phone with no sound indicator.

Sadly I only managed to recreate this with the Nexus 4 and mine is not booting now due to battery issues.

Lars Karlitski (larsu) wrote :

> the process exists itself, no other process sends SIGTERM.
> It just stops the loop and exists.

Ah sorry I misread the patch as adding those lines to the sigterm handler. Where does the warning about g_object_unref() come from then, though?

> I saw upstart tries to respawn, but only 3 times. After 3 times the result is
> a phone with no sound indicator.

You can change that (and the timing) in the upstart conf file `data/indicator-sound.conf.in`. (I can't believe I'm suggesting that you do this though ;) )

Please talk to Pete about how they fixed the issue in upstart. Seems other projects have this problem as well. I don't see how it makes sense to fix this only here.

Xavi Garcia (xavi-garcia-mena) wrote :

I already chatted with Pete about it.

It seems the problem was that upstart was not setting the DBUS env variables properly.
I checked that already and everything seems to be OK...

I know this is not a real solution, but meanwhile we move to systemd or fix the root issue in upstart I think it's best have a workaround that, at least, doesn't force the user to reboot the phone to get sound indicator.

Thanks for the "suggestion" on the upstart config file, I guess changing that would be enough.
I will go to a store this afternoon to get a screwdriver to remove my Nexus 4 battery and will give it a try.

Unmerged revisions

510. By Xavi Garcia on 2015-12-09

Modified time to wait

509. By Xavi Garcia on 2015-11-09

Added a retry mechanism to try to own the dbus name

508. By Xavi Garcia on 2015-11-04

Added some time before exiting the indicator if we've got an error owning the dbus name. This lets dbus system to fully start

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/main.c'
2--- src/main.c 2015-03-10 19:16:26 +0000
3+++ src/main.c 2015-12-09 13:36:30 +0000
4@@ -14,6 +14,8 @@
5 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6 */
7
8+#include <unistd.h>
9+
10 #include <glib.h>
11 #include <locale.h>
12 #include <libnotify/notify.h>
13@@ -22,6 +24,8 @@
14 #include "config.h"
15
16 static IndicatorSoundService * service = NULL;
17+static int DBUS_OWN_NAME_RETRIES = 30;
18+static GMainLoop * loop = NULL;
19
20 static gboolean
21 sigterm_handler (gpointer data)
22@@ -37,7 +41,16 @@
23 gpointer user_data)
24 {
25 g_warning("Name lost or unable to acquire bus: %s", name);
26- g_main_loop_quit((GMainLoop *)user_data);
27+ if (DBUS_OWN_NAME_RETRIES-- == 0) {
28+ g_main_loop_quit((GMainLoop *)user_data);
29+ } else {
30+ // we wait 10 milliseconds to let the system be completely up.
31+ // sometimes the indicator starts while dbus seems to be
32+ // still starting and if upstart is fast enough restarting
33+ // the indicator it may fail to start in the 30 upstart retries.
34+ usleep(10000);
35+ try_bus_own_name();
36+ }
37 }
38
39 static void
40@@ -66,11 +79,22 @@
41 g_clear_object(&accounts);
42 }
43
44+void
45+try_bus_own_name()
46+{
47+ g_bus_own_name(G_BUS_TYPE_SESSION,
48+ "com.canonical.indicator.sound",
49+ G_BUS_NAME_OWNER_FLAGS_NONE,
50+ on_bus_acquired,
51+ NULL, /* name acquired */
52+ on_name_lost,
53+ loop,
54+ NULL);
55+}
56+
57 int
58 main (int argc, char ** argv)
59 {
60- GMainLoop * loop = NULL;
61-
62 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
63 setlocale (LC_ALL, "");
64 bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
65@@ -83,14 +107,7 @@
66 /* Initialize libnotify */
67 notify_init ("indicator-sound");
68
69- g_bus_own_name(G_BUS_TYPE_SESSION,
70- "com.canonical.indicator.sound",
71- G_BUS_NAME_OWNER_FLAGS_NONE,
72- on_bus_acquired,
73- NULL, /* name acquired */
74- on_name_lost,
75- loop,
76- NULL);
77+ try_bus_own_name();
78
79 g_main_loop_run(loop);
80

Subscribers

People subscribed via source and target branches