Skip to content

Commit

Permalink
app_persistency: fix regression
Browse files Browse the repository at this point in the history
There was a blocking `.sync_all()` on drop to guarantee all data was
synced to the disk. Scheduling async tasks on a blocking context in
tokio is somewhat of a bad practice.

As a solution, the task is scheduled conventionally with 'tokio::spawn'.
This means there is no guarantee the task is executed before the exit of
the program. This is mitigated with a fast writeback timeout on changes.
  • Loading branch information
svenrademakers committed Jul 17, 2024
1 parent 0a4010c commit 5ba12b5
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/persistency/app_persistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use super::binary_persistency::PersistencyStore;
use anyhow::Context;
use futures::future::Either;
use tokio::fs::{File, OpenOptions};
use tokio::runtime::Handle;
use tokio::time::sleep_until;
const BIN_DATA: &str = "/var/lib/bmcd/bmcd.bin";

Expand Down Expand Up @@ -232,10 +231,7 @@ impl Drop for ApplicationPersistency {
fn drop(&mut self) {
let context = self.context.clone();

// block_on is used to make sure that the async code gets executed
// in place, preventing omission of the task during a tokio shutdown.
// Which would happen if it was scheduled with `tokio::spawn`.
Handle::current().block_on(async move {
tokio::spawn(async move {
if let Err(e) = context.sync_all().await {
tracing::error!("{}", e);
}
Expand Down

0 comments on commit 5ba12b5

Please sign in to comment.