[geary/wip/714104-refine-account-dialog: 63/69] Ensure SmtpClientService gets shut down correctly
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/714104-refine-account-dialog: 63/69] Ensure SmtpClientService gets shut down correctly
- Date: Fri, 30 Nov 2018 12:53:38 +0000 (UTC)
commit 2b8fbe23e5a7065d5bfe6b5628e65c49bc449666
Author: Michael Gratton <mike vee net>
Date: Wed Nov 28 22:12:40 2018 +1100
Ensure SmtpClientService gets shut down correctly
Pass the start() cancellable to fill_outbox_queue() so it doesn't
continue when cancelled, wait for the postie to exit when stopping and
before closing the outbox so that pending commands have a chance
to complete.
src/engine/smtp/smtp-client-service.vala | 61 ++++++++++++++++++--------------
1 file changed, 34 insertions(+), 27 deletions(-)
---
diff --git a/src/engine/smtp/smtp-client-service.vala b/src/engine/smtp/smtp-client-service.vala
index 61006c60..9cdfe62b 100644
--- a/src/engine/smtp/smtp-client-service.vala
+++ b/src/engine/smtp/smtp-client-service.vala
@@ -64,7 +64,7 @@ internal class Geary.Smtp.ClientService : Geary.ClientService {
throws GLib.Error {
this.is_running = true;
yield this.outbox.open_async(Folder.OpenFlags.NONE, cancellable);
- this.fill_outbox_queue.begin();
+ yield this.fill_outbox_queue(cancellable);
this.endpoint.connectivity.notify["is-reachable"].connect(
on_reachable_changed
);
@@ -86,6 +86,13 @@ internal class Geary.Smtp.ClientService : Geary.ClientService {
on_connectivity_error
);
this.stop_postie();
+ // Wait for the postie to actually stop before closing the
+ // folder so w don't interrupt e.g. sending/saving/deleting
+ // mail
+ while (this.queue_cancellable != null) {
+ GLib.Idle.add(this.stop.callback);
+ yield;
+ }
yield this.outbox.close_async(cancellable);
this.is_running = false;
}
@@ -104,28 +111,6 @@ internal class Geary.Smtp.ClientService : Geary.ClientService {
this.outbox_queue.send(id);
}
- /**
- * Loads any email in the outbox and adds them to the queue.
- */
- private async void fill_outbox_queue() {
- try {
- Gee.List<Email>? queued = yield this.outbox.list_email_by_id_async(
- null,
- int.MAX, // fetch all
- Email.Field.NONE, // ids only
- Folder.ListFlags.OLDEST_TO_NEWEST,
- this.queue_cancellable
- );
- if (queued != null) {
- foreach (Email email in queued) {
- this.outbox_queue.send(email.id);
- }
- }
- } catch (Error err) {
- warning("Error filling queue: %s", err.message);
- }
- }
-
/**
* Starts delivery of messages in the queue.
*/
@@ -198,7 +183,7 @@ internal class Geary.Smtp.ClientService : Geary.ClientService {
}
this.queue_cancellable = null;
- debug("Exiting outbox postie");
+ debug("Outbox postie exited");
}
/**
@@ -206,9 +191,31 @@ internal class Geary.Smtp.ClientService : Geary.ClientService {
*/
private void stop_postie() {
debug("Stopping outbox postie");
- Cancellable? old_cancellable = this.queue_cancellable;
- if (old_cancellable != null) {
- old_cancellable.cancel();
+ if (this.queue_cancellable != null) {
+ this.queue_cancellable.cancel();
+ }
+ }
+
+ /**
+ * Loads any email in the outbox and adds them to the queue.
+ */
+ private async void fill_outbox_queue(GLib.Cancellable cancellable) {
+ debug("Filling queue");
+ try {
+ Gee.List<Email>? queued = yield this.outbox.list_email_by_id_async(
+ null,
+ int.MAX, // fetch all
+ Email.Field.NONE, // ids only
+ Folder.ListFlags.OLDEST_TO_NEWEST,
+ cancellable
+ );
+ if (queued != null) {
+ foreach (Email email in queued) {
+ this.outbox_queue.send(email.id);
+ }
+ }
+ } catch (Error err) {
+ warning("Error filling queue: %s", err.message);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]