[geary] Force app close if shutdown hangs: Bug #745561



commit eb8fc9d352bb326b6d698d54a16014866c2817b8
Author: Jim Nelson <jim yorba org>
Date:   Thu Mar 26 15:21:11 2015 -0700

    Force app close if shutdown hangs: Bug #745561
    
    If Geary takes more than 5 seconds to shutdown cleanly, the process
    is forcibly closed.

 src/client/application/geary-application.vala |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/src/client/application/geary-application.vala b/src/client/application/geary-application.vala
index 672ddb8..9f8ca0f 100644
--- a/src/client/application/geary-application.vala
+++ b/src/client/application/geary-application.vala
@@ -43,6 +43,9 @@ public class GearyApplication : Gtk.Application {
         {ACTION_ENTRY_COMPOSE, activate_compose, "s"},
     };
     
+    private const int64 USEC_PER_SEC = 1000000;
+    private const int64 FORCE_SHUTDOWN_USEC = 5 * USEC_PER_SEC;
+    
     public static GearyApplication instance {
         get { return _instance; }
         private set {
@@ -335,10 +338,21 @@ public class GearyApplication : Gtk.Application {
             return;
         }
         
-        // Give asynchronous destroy_async() a chance to complete
+        // Give asynchronous destroy_async() a chance to complete, but to avoid bug(s) where
+        // Geary hangs at exit, shut the whole thing down if destroy_async() takes too long to
+        // complete
+        int64 start_usec = get_monotonic_time();
         destroy_async.begin();
-        while (!is_destroyed || Gtk.events_pending())
+        while (!is_destroyed || Gtk.events_pending()) {
             Gtk.main_iteration();
+            
+            int64 delta_usec = get_monotonic_time() - start_usec;
+            if (delta_usec >= FORCE_SHUTDOWN_USEC) {
+                debug("Forcing shutdown of Geary, %ss passed...", (delta_usec / USEC_PER_SEC).to_string());
+                
+                break;
+            }
+        }
         
         if (Gtk.main_level() > 0)
             Gtk.main_quit();


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