[geary/wip/prefetcher-missing-mail: 1/4] Ensure background sync ops are cancelled if the folder closes



commit 4ec936fe7cb939c3c4b4542c33db18a4bf89b307
Author: Michael Gratton <mike vee net>
Date:   Wed Aug 28 10:10:24 2019 +1000

    Ensure background sync ops are cancelled if the folder closes
    
    Since MinimalFolder.synchronize_remote() waits for the prefetcher to
    finish, but the prefetcher only closes when the folder closes, this
    could deadlock.

 .../imap-engine-account-synchronizer.vala          | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
---
diff --git a/src/engine/imap-engine/imap-engine-account-synchronizer.vala 
b/src/engine/imap-engine/imap-engine-account-synchronizer.vala
index 86098608..89cc77be 100644
--- a/src/engine/imap-engine/imap-engine-account-synchronizer.vala
+++ b/src/engine/imap-engine/imap-engine-account-synchronizer.vala
@@ -104,13 +104,29 @@ private class Geary.ImapEngine.AccountSynchronizer : Geary.BaseObject {
  */
 private class Geary.ImapEngine.RefreshFolderSync : FolderOperation {
 
+
+    GLib.Cancellable? closed_cancellable = null;
+
+
     internal RefreshFolderSync(GenericAccount account,
                                MinimalFolder folder) {
         base(account, folder);
+        this.folder.closed.connect(on_folder_close);
+    }
+
+    ~RefreshFolderSync() {
+        Geary.Folder? folder = this.folder;
+        if (folder != null) {
+            this.folder.closed.disconnect(on_folder_close);
+        }
     }
 
     public override async void execute(GLib.Cancellable cancellable)
         throws GLib.Error {
+        // Stash the cancellable so the op can cancel the sync if the
+        // folder closes.
+        this.closed_cancellable = cancellable;
+
         bool was_opened = false;
         MinimalFolder minimal = (MinimalFolder) this.folder;
         try {
@@ -189,6 +205,12 @@ private class Geary.ImapEngine.RefreshFolderSync : FolderOperation {
         }
     }
 
+    private void on_folder_close() {
+        if (this.closed_cancellable != null) {
+            this.closed_cancellable.cancel();
+        }
+    }
+
 }
 
 /**


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