Merge lp:~mhr3/libunity/remote-scope-fixes into lp:libunity

Proposed by Michal Hruby
Status: Merged
Approved by: Didier Roche-Tolomelli
Approved revision: 138
Merged at revision: 135
Proposed branch: lp:~mhr3/libunity/remote-scope-fixes
Merge into: lp:libunity
Diff against target: 201 lines (+73/-19)
5 files modified
src/unity-lens-private.vala (+8/-2)
src/unity-lens-tools.vala (+17/-2)
src/unity-scope-interface.vala (+6/-4)
src/unity-scope-private.vala (+5/-5)
src/unity-scope-proxy-remote.vala (+37/-6)
To merge this branch: bzr merge lp:~mhr3/libunity/remote-scope-fixes
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+102490@code.launchpad.net

Commit message

Restart crashed remote scopes and fix a couple of warnings when they do crash

Description of the change

There were a couple of issues with remote scopes:

1) We didn't restart them if they crashed
2) After the scope disappeared we tried to manipulate a filter model that was unreferenced
3) ScopeError was not registered as dbus error on first call to search/global_search

These issues caused warnings when a remote scope was killed and they are gone after applying these fixes.

To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Looks sensible. I am not sure if this is something we should test. Or I mean, we should, but if it's worth the (considerable) effort...

Revision history for this message
Michal Hruby (mhr3) wrote :

Yes, although we have tests where there's a lens and a remote scope talking to it, it's not registered as proper dbus service, so it can't be autostarted if it was killed. FWIW I tested all of this manually and the scopes restart now and warnings are gone, plus the changes don't touch any critical code paths for it to cause regressions.

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Agreed. I took another detailed review of the code and I agree that it looks both correct and safe.

review: Approve
Revision history for this message
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-libunity/117/console reported an error when processing this lp:~mhr3/libunity/remote-scope-fixes branch.
Not merging it.

Revision history for this message
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-libunity/118/console reported an error when processing this lp:~mhr3/libunity/remote-scope-fixes branch.
Not merging it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity-lens-private.vala'
2--- src/unity-lens-private.vala 2012-03-20 15:29:06 +0000
3+++ src/unity-lens-private.vala 2012-04-18 10:48:17 +0000
4@@ -265,8 +265,6 @@
5 {
6 ScopeProxy? scope = obj as ScopeProxy;
7
8- // FIXME: Remove existing receiver, if any
9-
10 /* Because we need to manipulate the filters straight away,
11 * we have to wait until it's synchronized
12 */
13@@ -279,6 +277,14 @@
14 }
15 else
16 _filters_sync.add_receiver (scope.filters_model);
17+
18+ // make sure we unregister the filter_model if it dies
19+ scope.filters_model.weak_ref ((WeakNotify) scope_filter_model_vanished);
20+ }
21+
22+ private void scope_filter_model_vanished (Dee.Model filter_model)
23+ {
24+ _filters_sync.remove_receiver (filter_model);
25 }
26
27 private void on_scope_sources_updated (Object obj, ParamSpec pspec)
28
29=== modified file 'src/unity-lens-tools.vala'
30--- src/unity-lens-tools.vala 2012-03-16 16:33:15 +0000
31+++ src/unity-lens-tools.vala 2012-04-18 10:48:17 +0000
32@@ -63,14 +63,29 @@
33
34 public void add_receiver (Dee.Model receiver)
35 {
36- receiver.clear();
37+ if (receiver in _receivers) return;
38+ receiver.clear ();
39
40 for (int i = 0; i < provider.get_n_rows(); ++i)
41 {
42 unowned Dee.ModelIter iter = provider.get_iter_at_row(i);
43 add_row(iter, receiver);
44 }
45- _receivers.add(receiver);
46+
47+ _receivers.add (receiver);
48+ }
49+
50+ public void remove_receiver (Dee.Model receiver)
51+ {
52+ int index = _receivers.index_of (receiver);
53+ if (index >= 0)
54+ {
55+ _receivers.remove_at (index);
56+ }
57+ else
58+ {
59+ warning ("Receiver [%p] was not registered", receiver);
60+ }
61 }
62
63 private void on_row_added (Dee.Model model, Dee.ModelIter iter)
64
65=== modified file 'src/unity-scope-interface.vala'
66--- src/unity-scope-interface.vala 2012-01-06 13:04:27 +0000
67+++ src/unity-scope-interface.vala 2012-04-18 10:48:17 +0000
68@@ -68,14 +68,16 @@
69 {
70 public abstract async void info_request () throws IOError;
71
72- public abstract async ActivationReplyRaw activate (string uri,
73- uint action_type) throws IOError;
74+ public abstract async ActivationReplyRaw activate (
75+ string uri, uint action_type) throws IOError;
76
77 public abstract async HashTable<string, Variant> search (
78- string search_string, HashTable<string, Variant> hints) throws Error;
79+ string search_string,
80+ HashTable<string, Variant> hints) throws IOError, ScopeError;
81
82 public abstract async HashTable<string, Variant> global_search (
83- string search_string, HashTable<string, Variant> hints) throws Error;
84+ string search_string,
85+ HashTable<string, Variant> hints) throws IOError, ScopeError;
86
87 public abstract async PreviewReplyRaw preview (string uri) throws IOError;
88
89
90=== modified file 'src/unity-scope-private.vala'
91--- src/unity-scope-private.vala 2012-02-13 19:33:59 +0000
92+++ src/unity-scope-private.vala 2012-04-18 10:48:17 +0000
93@@ -367,7 +367,7 @@
94
95 private async HashTable<string, Variant> search_internal (
96 string search_string, HashTable<string, Variant> hints,
97- SearchType search_type) throws Error
98+ SearchType search_type) throws ScopeError
99 {
100 HashTable<string, Variant> result =
101 new HashTable<string, Variant> (str_hash, str_equal);
102@@ -468,8 +468,8 @@
103 return result;
104 }
105
106- public async HashTable<string, Variant> search (
107- string search_string, HashTable<string, Variant> hints) throws Error
108+ public async HashTable<string, Variant> search (string search_string,
109+ HashTable<string, Variant> hints) throws IOError, ScopeError
110 {
111 HashTable<string, Variant> result;
112
113@@ -478,8 +478,8 @@
114 return result;
115 }
116
117- public async HashTable<string, Variant> global_search (
118- string search_string, HashTable<string, Variant> hints) throws Error
119+ public async HashTable<string, Variant> global_search (string search_string,
120+ HashTable<string, Variant> hints) throws IOError, ScopeError
121 {
122 HashTable<string, Variant> result;
123
124
125=== modified file 'src/unity-scope-proxy-remote.vala'
126--- src/unity-scope-proxy-remote.vala 2012-03-16 16:48:13 +0000
127+++ src/unity-scope-proxy-remote.vala 2012-04-18 10:48:17 +0000
128@@ -69,6 +69,8 @@
129 private Dee.SharedModel? _filters_model;
130 private uint _reconnection_id = 0;
131 private bool synchronized = false;
132+ private int64 _last_scope_crash = 0;
133+ private uint _scope_crashes = 0;
134
135 public ScopeProxyRemote (string dbus_name_, string dbus_path_)
136 {
137@@ -118,7 +120,6 @@
138 private void on_scope_vanished (DBusConnection conn,
139 string name)
140 {
141- /* FIXME: Add some protection against Scopes that keep restarting */
142 Trace.log_object (this, "Scope vanished: %s", dbus_name);
143
144 synchronized = false;
145@@ -130,10 +131,38 @@
146 if (_global_results_model != null)
147 _global_results_model.clear ();
148
149- if (_filters_model != null)
150- _filters_model.clear ();
151-
152- start_reconnection_timeout ();
153+ /* No need to clear the filters model, it's read-only for the scope and
154+ * it would just cause warnings from filters synchronizer */
155+ _filters_model = null;
156+
157+ if (_service != null)
158+ {
159+ /* Here comes the protected-restarting logic - the scope will be
160+ * restarted unless it crashed more than 10 times during the past
161+ * 15 minutes */
162+ _scope_crashes++;
163+ var cur_time = get_monotonic_time ();
164+ var time_since_last_crash = cur_time - _last_scope_crash;
165+
166+ if (time_since_last_crash >= 15*60000000) // 15 minutes
167+ {
168+ _last_scope_crash = cur_time;
169+ // reset crash counter, it's not that bad
170+ _scope_crashes = 1;
171+ }
172+ else if (_scope_crashes >= 10)
173+ {
174+ // more than 10 crashes in the past 15 minutes
175+ warning ("Scope %s is crashing too often, disabling it", dbus_name);
176+ return;
177+ }
178+
179+ start_reconnection_timeout ();
180+ }
181+ else
182+ {
183+ start_reconnection_timeout ();
184+ }
185 }
186
187 private void start_reconnection_timeout ()
188@@ -141,10 +170,12 @@
189 if (_reconnection_id != 0)
190 Source.remove (_reconnection_id);
191
192- _reconnection_id = Timeout.add_seconds (1, () =>
193+ _reconnection_id = Timeout.add_seconds (2, () =>
194 {
195 if (_service == null)
196 connect_to_scope ();
197+ else if ((_service as DBusProxy).g_name_owner == null)
198+ _service.info_request (); // ping the service to autostart it
199
200 _reconnection_id = 0;
201 return false;

Subscribers

People subscribed via source and target branches