imap: prevent deadlock in operations.rs

imap/operations.rs could deadlock with imap/watch.rs when both lock the
main IMAP connection but both also need to lock UIDStore
memfd
Manos Pitsidianakis 2020-03-25 13:12:02 +02:00
parent 4c32bf450d
commit c77af98b26
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
1 changed files with 4 additions and 0 deletions

View File

@ -75,6 +75,8 @@ impl BackendOp for ImapOp {
if cache.bytes.is_some() {
self.bytes = cache.bytes.clone();
} else {
drop(cache);
drop(bytes_cache);
let mut response = String::with_capacity(8 * 1024);
{
let mut conn = self.connection.lock().unwrap();
@ -93,6 +95,8 @@ impl BackendOp for ImapOp {
} = protocol_parser::uid_fetch_response(&response)?.1;
assert_eq!(uid, self.uid);
assert!(body.is_some());
let mut bytes_cache = self.uid_store.byte_cache.lock()?;
let cache = bytes_cache.entry(self.uid).or_default();
if let Some((flags, _)) = flags {
self.flags.set(Some(flags));
cache.flags = Some(flags);