aboutsummaryrefslogtreecommitdiff
path: root/src/mail/incoming.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-07-01 19:33:47 +0200
committerAlex Auvolat <alex@adnab.me>2022-07-01 19:33:47 +0200
commita8e33383f481441f77af9a39e12749e90879029c (patch)
tree47b8a4a8e9d7758df9964e68c9473be60f400b0d /src/mail/incoming.rs
parente93732d9bb664995d383e9d1ae34206d72dec699 (diff)
downloadaerogramme-a8e33383f481441f77af9a39e12749e90879029c.tar.gz
aerogramme-a8e33383f481441f77af9a39e12749e90879029c.zip
release lock when no longer needed
Diffstat (limited to 'src/mail/incoming.rs')
-rw-r--r--src/mail/incoming.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/mail/incoming.rs b/src/mail/incoming.rs
index d40459c..5b0da12 100644
--- a/src/mail/incoming.rs
+++ b/src/mail/incoming.rs
@@ -8,7 +8,7 @@ use futures::{future::BoxFuture, Future, FutureExt};
use k2v_client::{CausalValue, CausalityToken, K2vClient, K2vValue};
use rusoto_s3::{PutObjectRequest, S3Client, S3};
use tokio::sync::watch;
-use tracing::{error, info};
+use tracing::{error, info, warn};
use crate::cryptoblob;
use crate::login::{Credentials, PublicCredentials};
@@ -285,7 +285,23 @@ async fn k2v_lock_loop_internal(
.boxed();
let res = futures::try_join!(watch_lock_loop, lock_notify_loop, take_lock_loop);
- info!("lock loop exited: {:?}", res);
+
+ info!("lock loop exited: {:?}, releasing", res);
+
+ if !held_tx.is_closed() {
+ warn!("wierd...");
+ let _ = held_tx.send(false);
+ }
+
+ // If lock is ours, release it
+ let release = match &*state_rx.borrow() {
+ LockState::Held(pid, _, ct) if *pid == our_pid => Some(ct.clone()),
+ _ => None,
+ };
+ if let Some(ct) = release {
+ let _ = k2v.delete_item(pk, sk, ct.clone()).await;
+ }
+
}
// ---- UTIL: function to wait for a value to have changed in K2V ----