Fix concurrent write bug for session.json
This commit is contained in:
parent
6823490803
commit
673f59009a
1 changed files with 3 additions and 2 deletions
|
|
@ -85,6 +85,8 @@ impl JsonSessionPersistenceStore {
|
|||
}
|
||||
|
||||
async fn flush(&self) -> anyhow::Result<()> {
|
||||
// we don't need the write lock technically, but we need to stop concurrent modifications
|
||||
let db_content = self.db_content.write().await;
|
||||
let tmp_filename = format!("{}.tmp", self.db_filename.to_str().unwrap());
|
||||
let mut tmp = tokio::fs::OpenOptions::new()
|
||||
.create(true)
|
||||
|
|
@ -96,8 +98,7 @@ impl JsonSessionPersistenceStore {
|
|||
trace!(?tmp_filename, "opened temp file");
|
||||
|
||||
let mut buf = Vec::new();
|
||||
serde_json::to_writer(&mut buf, &*self.db_content.read().await)
|
||||
.context("error serializing")?;
|
||||
serde_json::to_writer(&mut buf, &*db_content).context("error serializing")?;
|
||||
|
||||
trace!(?tmp_filename, "serialized DB as JSON");
|
||||
tmp.write_all(&buf)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue