[geary/wip/controller-cleanup] Fix application controller construction race



commit 99e12ce118bddc7983ed03c8ce263aff70e9978c
Author: Michael Gratton <mike vee net>
Date:   Sun Apr 21 15:50:16 2019 +1000

    Fix application controller construction race
    
    Fix multiple controller instances being constructed if multiple actions
    are executed at once.

 src/client/application/geary-application.vala | 40 +++++++++++++--------------
 1 file changed, 20 insertions(+), 20 deletions(-)
---
diff --git a/src/client/application/geary-application.vala b/src/client/application/geary-application.vala
index 1b9e6edd..69d00b97 100644
--- a/src/client/application/geary-application.vala
+++ b/src/client/application/geary-application.vala
@@ -660,9 +660,7 @@ public class GearyApplication : Gtk.Application {
     // Presents a main window. If the controller is not open, opens it
     // first.
     private async void present() {
-        if (this.controller == null) {
-            yield create_controller();
-        }
+        yield create_controller();
         this.controller.main_window.present();
     }
 
@@ -673,21 +671,21 @@ public class GearyApplication : Gtk.Application {
         // hit the yield below, before we create the main window.
         hold();
 
-        // do *after* parsing args, as they dicate where logging is
-        // sent to, if anywhere, and only after activate (which means
-        // this is only logged for the one user-visible instance, not
-        // the other instances called when sending commands to the app
-        // via the command-line)
-        message(
-            "%s %s prefix=%s exec_dir=%s is_installed=%s",
-            NAME, VERSION, INSTALL_PREFIX,
-            exec_dir.get_path(),
-            this.is_installed.to_string()
-        );
+        lock (this.controller) {
+            if (this.controller == null) {
+                message(
+                    "%s %s prefix=%s exec_dir=%s is_installed=%s",
+                    NAME, VERSION, INSTALL_PREFIX,
+                    exec_dir.get_path(),
+                    this.is_installed.to_string()
+                );
+
+                this.controller = yield new Application.Controller(
+                    this, this.controller_cancellable
+                );
+            }
+        }
 
-        this.controller = yield new Application.Controller(
-            this, this.controller_cancellable
-        );
         release();
     }
 
@@ -696,9 +694,11 @@ public class GearyApplication : Gtk.Application {
         // see create_controller() for reasoning hold/release is used
         hold();
 
-        if (this.controller != null) {
-            yield this.controller.close_async();
-            this.controller = null;
+        lock (this.controller) {
+            if (this.controller != null) {
+                yield this.controller.close_async();
+                this.controller = null;
+            }
         }
 
         release();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]