[geary/wip/goa-error-when-disconnected: 3/3] Fix GOA accounts throwing an error when starting offline



commit 82160e9ff4bf2b656274194acc20f410f0beee87
Author: Michael Gratton <mike vee net>
Date:   Sun Mar 3 22:20:41 2019 +1100

    Fix GOA accounts throwing an error when starting offline
    
    Don't check service credentials are loaded when the account is being
    opened, since GOA accounts will do a
    org.gnome.OnlineAccounts.Account::EnsureCredentials() call, and this
    will error out if the creds are invalid or not available.
    
    Instead, check when we know that the services should be reachable, and
    hope that means the GOA provider's auth service is reachable, too.

 src/engine/imap-engine/imap-engine-generic-account.vala |  5 -----
 src/engine/imap/api/imap-client-service.vala            | 14 ++++++++++++++
 src/engine/smtp/smtp-client-service.vala                |  4 ++++
 3 files changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala 
b/src/engine/imap-engine/imap-engine-generic-account.vala
index b9b36fff..567887d6 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -160,11 +160,6 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
             new LoadFolders(this, this.local, get_supported_special_folders())
         );
 
-        // To prevent spurious connection failures, we make sure we
-        // have passwords before attempting a connection.
-        yield this.information.load_incoming_credentials(cancellable);
-        yield this.information.load_outgoing_credentials(cancellable);
-
         // Start the mail services. Start incoming directly, but queue
         // outgoing so local folders can be loaded first in case
         // queued mail gets sent and needs to get saved somewhere.
diff --git a/src/engine/imap/api/imap-client-service.vala b/src/engine/imap/api/imap-client-service.vala
index fa99d478..3b36043c 100644
--- a/src/engine/imap/api/imap-client-service.vala
+++ b/src/engine/imap/api/imap-client-service.vala
@@ -265,6 +265,20 @@ internal class Geary.Imap.ClientService : Geary.ClientService {
         debug("Checking session pool with %d of %d free",
               this.free_queue.size, this.all_sessions.size);
 
+        if (!is_claiming) {
+            // To prevent spurious connection failures, ensure tokens
+            // are up-to-date before attempting a connection, but
+            // after we know we should be able to connect to it
+            try {
+                yield this.account.load_incoming_credentials(
+                    this.pool_cancellable
+                );
+            } catch (GLib.Error err) {
+                notify_connection_failed(new ErrorContext(err));
+                return;
+            }
+        }
+
         int needed = this.min_pool_size - this.all_sessions.size;
         if (needed <= 0 && is_claiming) {
             needed = 1;
diff --git a/src/engine/smtp/smtp-client-service.vala b/src/engine/smtp/smtp-client-service.vala
index e949338a..bd22190a 100644
--- a/src/engine/smtp/smtp-client-service.vala
+++ b/src/engine/smtp/smtp-client-service.vala
@@ -188,6 +188,10 @@ internal class Geary.Smtp.ClientService : Geary.ClientService {
     // Returns true if email was successfully processed, else false
     private async void process_email(EmailIdentifier id, Cancellable cancellable)
         throws GLib.Error {
+        // To prevent spurious connection failures, ensure tokens are
+        // up-to-date before attempting to send the email
+        yield this.account.load_outgoing_credentials(cancellable);
+
         Email? email = null;
         try {
             email = yield this.outbox.fetch_email_async(


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