Skip to content

Commit 6187f13

Browse files
committed
fix(memory-connection-limits): make memory limit exclusive
1 parent a129a6f commit 6187f13

File tree

7 files changed

+10
-6
lines changed

7 files changed

+10
-6
lines changed

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
@@ -87,7 +87,7 @@ libp2p-identify = { version = "0.47.0", path = "protocols/identify" }
8787
libp2p-identity = { version = "0.2.12" }
8888
libp2p-kad = { version = "0.49.0", path = "protocols/kad" }
8989
libp2p-mdns = { version = "0.48.0", path = "protocols/mdns" }
90-
libp2p-memory-connection-limits = { version = "0.5.0", path = "misc/memory-connection-limits" }
90+
libp2p-memory-connection-limits = { version = "0.5.1", path = "misc/memory-connection-limits" }
9191
libp2p-metrics = { version = "0.17.0", path = "misc/metrics" }
9292
libp2p-mplex = { version = "0.43.1", path = "muxers/mplex" }
9393
libp2p-noise = { version = "0.46.1", path = "transports/noise" }

misc/memory-connection-limits/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.1
2+
3+
- fix limit checking according to documentation, limit should be reached not exceeded.
4+
See [PR XXXX](https://github.com/libp2p/rust-libp2p/pull/XXXX).
15
## 0.5.0
26

37
<!-- Update to libp2p-swarm v0.47.0 -->

misc/memory-connection-limits/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "libp2p-memory-connection-limits"
33
edition.workspace = true
44
rust-version = { workspace = true }
55
description = "Memory usage based connection limits for libp2p."
6-
version = "0.5.0"
6+
version = "0.5.1"
77
license = "MIT"
88
repository = "https://github.com/libp2p/rust-libp2p"
99
keywords = ["peer-to-peer", "libp2p", "networking"]

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use util::*;
3232
#[tokio::test]
3333
async fn max_bytes() {
3434
const CONNECTION_LIMIT: usize = 20;
35-
let max_allowed_bytes = CONNECTION_LIMIT * 1024 * 1024;
35+
let max_allowed_bytes = (CONNECTION_LIMIT - 1) * 1024 * 1024;
3636

3737
let mut network = Swarm::new_ephemeral_tokio(|_| TestBehaviour {
3838
connection_limits: Behaviour::with_max_bytes(max_allowed_bytes),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ 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-
let max_allowed_bytes = current_mem + CONNECTION_LIMIT * 1024 * 1024;
62+
let max_allowed_bytes = current_mem + (CONNECTION_LIMIT - 1) * 1024 * 1024;
6363
network.behaviour_mut().connection_limits = Behaviour::with_max_percentage(
6464
max_allowed_bytes as f64 / system_info.total_memory() as f64,
6565
);

0 commit comments

Comments
 (0)