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
=== modified file 'src/unity-lens-private.vala'
--- src/unity-lens-private.vala 2012-03-20 15:29:06 +0000
+++ src/unity-lens-private.vala 2012-04-18 10:48:17 +0000
@@ -265,8 +265,6 @@
265 {265 {
266 ScopeProxy? scope = obj as ScopeProxy;266 ScopeProxy? scope = obj as ScopeProxy;
267 267
268 // FIXME: Remove existing receiver, if any
269
270 /* Because we need to manipulate the filters straight away,268 /* Because we need to manipulate the filters straight away,
271 * we have to wait until it's synchronized269 * we have to wait until it's synchronized
272 */270 */
@@ -279,6 +277,14 @@
279 }277 }
280 else278 else
281 _filters_sync.add_receiver (scope.filters_model);279 _filters_sync.add_receiver (scope.filters_model);
280
281 // make sure we unregister the filter_model if it dies
282 scope.filters_model.weak_ref ((WeakNotify) scope_filter_model_vanished);
283 }
284
285 private void scope_filter_model_vanished (Dee.Model filter_model)
286 {
287 _filters_sync.remove_receiver (filter_model);
282 }288 }
283289
284 private void on_scope_sources_updated (Object obj, ParamSpec pspec)290 private void on_scope_sources_updated (Object obj, ParamSpec pspec)
285291
=== modified file 'src/unity-lens-tools.vala'
--- src/unity-lens-tools.vala 2012-03-16 16:33:15 +0000
+++ src/unity-lens-tools.vala 2012-04-18 10:48:17 +0000
@@ -63,14 +63,29 @@
6363
64 public void add_receiver (Dee.Model receiver)64 public void add_receiver (Dee.Model receiver)
65 {65 {
66 receiver.clear();66 if (receiver in _receivers) return;
67 receiver.clear ();
67 68
68 for (int i = 0; i < provider.get_n_rows(); ++i)69 for (int i = 0; i < provider.get_n_rows(); ++i)
69 {70 {
70 unowned Dee.ModelIter iter = provider.get_iter_at_row(i);71 unowned Dee.ModelIter iter = provider.get_iter_at_row(i);
71 add_row(iter, receiver);72 add_row(iter, receiver);
72 }73 }
73 _receivers.add(receiver);74
75 _receivers.add (receiver);
76 }
77
78 public void remove_receiver (Dee.Model receiver)
79 {
80 int index = _receivers.index_of (receiver);
81 if (index >= 0)
82 {
83 _receivers.remove_at (index);
84 }
85 else
86 {
87 warning ("Receiver [%p] was not registered", receiver);
88 }
74 }89 }
7590
76 private void on_row_added (Dee.Model model, Dee.ModelIter iter)91 private void on_row_added (Dee.Model model, Dee.ModelIter iter)
7792
=== modified file 'src/unity-scope-interface.vala'
--- src/unity-scope-interface.vala 2012-01-06 13:04:27 +0000
+++ src/unity-scope-interface.vala 2012-04-18 10:48:17 +0000
@@ -68,14 +68,16 @@
68{68{
69 public abstract async void info_request () throws IOError;69 public abstract async void info_request () throws IOError;
7070
71 public abstract async ActivationReplyRaw activate (string uri,71 public abstract async ActivationReplyRaw activate (
72 uint action_type) throws IOError;72 string uri, uint action_type) throws IOError;
7373
74 public abstract async HashTable<string, Variant> search (74 public abstract async HashTable<string, Variant> search (
75 string search_string, HashTable<string, Variant> hints) throws Error;75 string search_string,
76 HashTable<string, Variant> hints) throws IOError, ScopeError;
7677
77 public abstract async HashTable<string, Variant> global_search (78 public abstract async HashTable<string, Variant> global_search (
78 string search_string, HashTable<string, Variant> hints) throws Error;79 string search_string,
80 HashTable<string, Variant> hints) throws IOError, ScopeError;
79 81
80 public abstract async PreviewReplyRaw preview (string uri) throws IOError;82 public abstract async PreviewReplyRaw preview (string uri) throws IOError;
81 83
8284
=== modified file 'src/unity-scope-private.vala'
--- src/unity-scope-private.vala 2012-02-13 19:33:59 +0000
+++ src/unity-scope-private.vala 2012-04-18 10:48:17 +0000
@@ -367,7 +367,7 @@
367367
368 private async HashTable<string, Variant> search_internal (368 private async HashTable<string, Variant> search_internal (
369 string search_string, HashTable<string, Variant> hints,369 string search_string, HashTable<string, Variant> hints,
370 SearchType search_type) throws Error370 SearchType search_type) throws ScopeError
371 {371 {
372 HashTable<string, Variant> result =372 HashTable<string, Variant> result =
373 new HashTable<string, Variant> (str_hash, str_equal);373 new HashTable<string, Variant> (str_hash, str_equal);
@@ -468,8 +468,8 @@
468 return result;468 return result;
469 }469 }
470470
471 public async HashTable<string, Variant> search (471 public async HashTable<string, Variant> search (string search_string,
472 string search_string, HashTable<string, Variant> hints) throws Error472 HashTable<string, Variant> hints) throws IOError, ScopeError
473 {473 {
474 HashTable<string, Variant> result;474 HashTable<string, Variant> result;
475475
@@ -478,8 +478,8 @@
478 return result;478 return result;
479 }479 }
480480
481 public async HashTable<string, Variant> global_search (481 public async HashTable<string, Variant> global_search (string search_string,
482 string search_string, HashTable<string, Variant> hints) throws Error482 HashTable<string, Variant> hints) throws IOError, ScopeError
483 {483 {
484 HashTable<string, Variant> result;484 HashTable<string, Variant> result;
485485
486486
=== modified file 'src/unity-scope-proxy-remote.vala'
--- src/unity-scope-proxy-remote.vala 2012-03-16 16:48:13 +0000
+++ src/unity-scope-proxy-remote.vala 2012-04-18 10:48:17 +0000
@@ -69,6 +69,8 @@
69 private Dee.SharedModel? _filters_model;69 private Dee.SharedModel? _filters_model;
70 private uint _reconnection_id = 0;70 private uint _reconnection_id = 0;
71 private bool synchronized = false;71 private bool synchronized = false;
72 private int64 _last_scope_crash = 0;
73 private uint _scope_crashes = 0;
7274
73 public ScopeProxyRemote (string dbus_name_, string dbus_path_)75 public ScopeProxyRemote (string dbus_name_, string dbus_path_)
74 {76 {
@@ -118,7 +120,6 @@
118 private void on_scope_vanished (DBusConnection conn,120 private void on_scope_vanished (DBusConnection conn,
119 string name)121 string name)
120 {122 {
121 /* FIXME: Add some protection against Scopes that keep restarting */
122 Trace.log_object (this, "Scope vanished: %s", dbus_name);123 Trace.log_object (this, "Scope vanished: %s", dbus_name);
123124
124 synchronized = false;125 synchronized = false;
@@ -130,10 +131,38 @@
130 if (_global_results_model != null)131 if (_global_results_model != null)
131 _global_results_model.clear ();132 _global_results_model.clear ();
132133
133 if (_filters_model != null)134 /* No need to clear the filters model, it's read-only for the scope and
134 _filters_model.clear ();135 * it would just cause warnings from filters synchronizer */
135136 _filters_model = null;
136 start_reconnection_timeout ();137
138 if (_service != null)
139 {
140 /* Here comes the protected-restarting logic - the scope will be
141 * restarted unless it crashed more than 10 times during the past
142 * 15 minutes */
143 _scope_crashes++;
144 var cur_time = get_monotonic_time ();
145 var time_since_last_crash = cur_time - _last_scope_crash;
146
147 if (time_since_last_crash >= 15*60000000) // 15 minutes
148 {
149 _last_scope_crash = cur_time;
150 // reset crash counter, it's not that bad
151 _scope_crashes = 1;
152 }
153 else if (_scope_crashes >= 10)
154 {
155 // more than 10 crashes in the past 15 minutes
156 warning ("Scope %s is crashing too often, disabling it", dbus_name);
157 return;
158 }
159
160 start_reconnection_timeout ();
161 }
162 else
163 {
164 start_reconnection_timeout ();
165 }
137 }166 }
138167
139 private void start_reconnection_timeout ()168 private void start_reconnection_timeout ()
@@ -141,10 +170,12 @@
141 if (_reconnection_id != 0)170 if (_reconnection_id != 0)
142 Source.remove (_reconnection_id);171 Source.remove (_reconnection_id);
143172
144 _reconnection_id = Timeout.add_seconds (1, () =>173 _reconnection_id = Timeout.add_seconds (2, () =>
145 {174 {
146 if (_service == null)175 if (_service == null)
147 connect_to_scope ();176 connect_to_scope ();
177 else if ((_service as DBusProxy).g_name_owner == null)
178 _service.info_request (); // ping the service to autostart it
148179
149 _reconnection_id = 0;180 _reconnection_id = 0;
150 return false;181 return false;

Subscribers

People subscribed via source and target branches