[geary/wip/713006-better-error-reporting] Report IMAP connection errors, don't endlessly retry to connect.



commit 733def66347a322efea2a7d9920ac1b60bf0692b
Author: Michael James Gratton <mike vee net>
Date:   Mon Nov 13 10:35:40 2017 +1100

    Report IMAP connection errors, don't endlessly retry to connect.
    
    * src/engine/imap/transport/imap-client-session-manager.vala
      (ClientSessionManager): Add new connection_failed signal, remove the
      retry timer and simply report a connection error via the new signal.
    
    * src/engine/imap/api/imap-account.vala (Account): Listen to new signal,
      send a problem report through when a connection error occurs.

 src/engine/imap/api/imap-account.vala              |   11 ++++
 .../transport/imap-client-session-manager.vala     |   50 ++++++-------------
 2 files changed, 27 insertions(+), 34 deletions(-)
---
diff --git a/src/engine/imap/api/imap-account.vala b/src/engine/imap/api/imap-account.vala
index 46218ee..05f98e4 100644
--- a/src/engine/imap/api/imap-account.vala
+++ b/src/engine/imap/api/imap-account.vala
@@ -61,6 +61,7 @@ private class Geary.Imap.Account : BaseObject {
         this.account = account;
         this.session_mgr = new ClientSessionManager(account);
         this.session_mgr.ready.connect(on_session_ready);
+        this.session_mgr.connection_failed.connect(on_connection_failed);
         this.session_mgr.login_failed.connect(on_login_failed);
     }
 
@@ -633,6 +634,16 @@ private class Geary.Imap.Account : BaseObject {
         ready();
     }
 
+    private void on_connection_failed(Error error) {
+        // There was an error connecting to the IMAP host
+        this.authentication_failures = 0;
+        if (!(error is IOError.CANCELLED)) {
+            // XXX check the type of the error and report a more
+            // fine-grained problem here
+            report_problem(Geary.Account.Problem.RECV_EMAIL_ERROR, error);
+        }
+    }
+
     private void on_login_failed(Geary.Imap.StatusResponse? response) {
         this.authentication_failures++;
         if (this.authentication_failures >= Geary.Account.AUTH_ATTEMPTS_MAX) {
diff --git a/src/engine/imap/transport/imap-client-session-manager.vala 
b/src/engine/imap/transport/imap-client-session-manager.vala
index e3fdbe2..a02b6d5 100644
--- a/src/engine/imap/transport/imap-client-session-manager.vala
+++ b/src/engine/imap/transport/imap-client-session-manager.vala
@@ -1,16 +1,15 @@
 /*
- * Copyright 2017 Michael Gratton <mike vee net>
  * Copyright 2016 Software Freedom Conservancy Inc.
+ * Copyright 2017 Michael Gratton <mike vee net>
  *
  * This software is licensed under the GNU Lesser General Public License
  * (version 2.1 or later).  See the COPYING file in this distribution.
  */
 
 public class Geary.Imap.ClientSessionManager : BaseObject {
+
     private const int DEFAULT_MIN_POOL_SIZE = 1;
     private const int POOL_START_TIMEOUT_SEC = 4;
-    private const int POOL_RETRY_MIN_TIMEOUT_SEC = 1;
-    private const int POOL_RETRY_MAX_TIMEOUT_SEC = 10;
     private const int POOL_STOP_TIMEOUT_SEC = 1;
 
     /** Determines if the manager has been opened. */
@@ -69,7 +68,6 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
     private bool untrusted_host = false;
 
     private TimeoutManager pool_start;
-    private TimeoutManager pool_retry;
     private TimeoutManager pool_stop;
 
     /**
@@ -81,6 +79,9 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
      */
     public signal void ready();
 
+    /** Fired when a network or non-auth error occurs opening a session. */
+    public signal void connection_failed(Error err);
+
     /** Fired when an authentication error occurs opening a session. */
     public signal void login_failed(StatusResponse? response);
 
@@ -100,11 +101,6 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
             () => { this.adjust_session_pool.begin(); }
         );
 
-        this.pool_retry = new TimeoutManager.seconds(
-            POOL_RETRY_MIN_TIMEOUT_SEC,
-            () => { this.adjust_session_pool.begin(); }
-        );
-
         this.pool_stop = new TimeoutManager.seconds(
             POOL_STOP_TIMEOUT_SEC,
             () => { this.force_disconnect_all.begin(); }
@@ -142,7 +138,6 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
         this.is_ready = false;
 
         this.pool_start.reset();
-        this.pool_retry.reset();
         this.pool_stop.reset();
 
                this.endpoint.connectivity.notify["is-reachable"].disconnect(on_connectivity_change);
@@ -210,8 +205,17 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
             && !this.authentication_failed
             && !this.untrusted_host
             && this.endpoint.connectivity.is_reachable) {
-            pending_sessions++;
-            create_new_authorized_session.begin(null, on_created_new_authorized_session);
+            this.pending_sessions++;
+            create_new_authorized_session.begin(
+                null,
+                (obj, res) => {
+                    this.pending_sessions--;
+                    try {
+                        this.create_new_authorized_session.end(res);
+                    } catch (Error err) {
+                        connection_failed(err);
+                    }
+                });
         }
 
         try {
@@ -221,24 +225,6 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
         }
     }
 
-    private void on_created_new_authorized_session(Object? source, AsyncResult result) {
-        this.pending_sessions--;
-
-        try {
-            this.create_new_authorized_session.end(result);
-            this.pool_retry.reset();
-        } catch (Error err) {
-            debug("Unable to create authorized session to %s: %s", endpoint.to_string(), err.message);
-
-            // try again after a slight delay and bump up delay
-            this.pool_retry.start();
-            this.pool_retry.interval = (this.pool_retry.interval * 2).clamp(
-                POOL_RETRY_MIN_TIMEOUT_SEC,
-                POOL_RETRY_MAX_TIMEOUT_SEC
-            );
-        }
-    }
-
     private async ClientSession create_new_authorized_session(Cancellable? cancellable) throws Error {
         if (authentication_failed)
             throw new ImapError.UNAUTHENTICATED("Invalid ClientSessionManager credentials");
@@ -302,9 +288,6 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
             ready();
         }
 
-        // reset delay
-        this.pool_retry.interval = POOL_RETRY_MIN_TIMEOUT_SEC;
-
         // do this after logging in
         new_session.enable_keepalives(selected_keepalive_sec, unselected_keepalive_sec,
             selected_with_idle_keepalive_sec);
@@ -573,7 +556,6 @@ public class Geary.Imap.ClientSessionManager : BaseObject {
             this.pool_start.reset();
             this.pool_stop.start();
         }
-        this.pool_retry.reset();
        }
 
     /**


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