Skip to content

Commit bc71415

Browse files
committed
Merge branch 'fix-connection-memory-limits' of github.com:jxs/rust-libp2p into fix-connection-memory-limits
2 parents 4531898 + de4fe2f commit bc71415

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

misc/memory-connection-limits/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl Behaviour {
115115
fn check_limit(&mut self) -> Result<(), ConnectionDenied> {
116116
self.refresh_memory_stats_if_needed();
117117

118-
if self.process_physical_memory_bytes >= self.max_allowed_bytes {
118+
if self.process_physical_memory_bytes > self.max_allowed_bytes {
119119
return Err(ConnectionDenied::new(MemoryUsageLimitExceeded {
120120
process_physical_memory_bytes: self.process_physical_memory_bytes,
121121
max_allowed_bytes: self.max_allowed_bytes,

misc/memory-connection-limits/tests/max_bytes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ use util::*;
3131

3232
#[tokio::test]
3333
async fn max_bytes() {
34+
// These tests use connections as unit to test the memory limit.
35+
// Each connection consumes approximately 1MB of memory, so we give
36+
// one connection as buffer for test stability (CONNECTION_LIMIT - 1) on line 35.
3437
const CONNECTION_LIMIT: usize = 20;
3538
let max_allowed_bytes = (CONNECTION_LIMIT - 1) * 1024 * 1024;
3639

misc/memory-connection-limits/tests/max_percentage.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ async fn max_percentage() {
5959

6060
// Adds current mem usage to the limit and update
6161
let current_mem = memory_stats::memory_stats().unwrap().physical_mem;
62+
// These tests use connections as unit to test the memory limit.
63+
// Each connection consumes approximately 1MB of memory, so we give
64+
// one connection as buffer for test stability (CONNECTION_LIMIT - 1) on line 35.
6265
let max_allowed_bytes = current_mem + (CONNECTION_LIMIT - 1) * 1024 * 1024;
6366
network.behaviour_mut().connection_limits = Behaviour::with_max_percentage(
6467
max_allowed_bytes as f64 / system_info.total_memory() as f64,

0 commit comments

Comments
 (0)