From e0e68ce76d8dc0603e357366ff09b89a7a7bd579 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Sun, 14 Nov 2021 10:10:55 +0000 Subject: [PATCH] Fix double-locking bug in flush() --- yama/src/pile/local_sqlitebloblogs.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/yama/src/pile/local_sqlitebloblogs.rs b/yama/src/pile/local_sqlitebloblogs.rs index 5cb13d4..d9e74a3 100644 --- a/yama/src/pile/local_sqlitebloblogs.rs +++ b/yama/src/pile/local_sqlitebloblogs.rs @@ -527,14 +527,20 @@ impl RawPile for SqliteBloblogPile { Ok(Box::new(ki)) } fn flush(&self) -> anyhow::Result<()> { - let inner = self.inner.lock().unwrap(); - let _inner = self - .writers_reach_zero - .wait_while(inner, |inner| inner.writers_in_progress != 0) - .unwrap(); - + // must do this before we lock inner. self.flush_queued_pointer_writes()?; + let inner = self.inner.lock().unwrap(); + + if inner.writers_in_progress > 0 { + let _inner = self + .writers_reach_zero + .wait_while(inner, |inner| { + inner.writers_in_progress != 0 + }) + .unwrap(); + } + // TODO sync all files we have open first! sync(); Ok(())