Skip to content

Commit 3a9a283

Browse files
committed
Limit maximum dirty log size
Limit dirty log growth when files synchronization fails to prevent unbounded memory consumption.
1 parent 0725ed2 commit 3a9a283

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "historyprovider"
33
description = "historyprovider-rs"
44
license = "MIT"
55
repository = "https://github.com/silicon-heaven/historyprovider-rs"
6-
version = "2.12.2"
6+
version = "2.13.0"
77
edition = "2024"
88

99
[profile.release]

src/dirtylog.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::{HashMap, HashSet, VecDeque};
22
use std::path::{Path, PathBuf};
33
use std::pin::Pin;
4-
use std::sync::Arc;
4+
use std::sync::{Arc, OnceLock};
55

66
use futures::channel::mpsc::UnboundedReceiver;
77
use futures::channel::oneshot::Sender as OneshotSender;
@@ -100,6 +100,25 @@ pub(crate) async fn dirtylog_task(
100100
return;
101101
}
102102
};
103+
if let Ok(metadata) = dirty_log_file.metadata().await {
104+
let size = metadata.len();
105+
106+
static DIRTY_LOG_SIZE_MAX: OnceLock<u64> = OnceLock::new();
107+
let max_size = *DIRTY_LOG_SIZE_MAX.get_or_init(|| {
108+
std::env::var("DIRTY_LOG_SIZE_MAX")
109+
.ok()
110+
.and_then(|val| val.parse::<u64>().ok())
111+
.unwrap_or(100 * 1024 * 1024)
112+
});
113+
114+
if size > max_size {
115+
warn!(
116+
"Dirty log {path} max size exceeded ({size} > {max_size}), dropping journal entry {journal_entry:?}",
117+
path = dirty_log_path.display()
118+
);
119+
return;
120+
}
121+
}
103122
let mut writer = JournalWriterLog2::new(dirty_log_file.compat());
104123
writer.append(&journal_entry)
105124
.await

0 commit comments

Comments
 (0)