Skip to content

Commit 3933a11

Browse files
authored
Merge pull request #1028 from 0xMimir/bugfix/window-size
Refactor window size update to prevent underflow in stream
2 parents 9d5441a + 3afc60b commit 3933a11

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

p2p/src/network/yamux/p2p_network_yamux_reducer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ impl P2pNetworkYamuxState {
216216
if let Some(stream) = yamux_state.streams.get_mut(&frame.stream_id) {
217217
// must not underflow
218218
// TODO: check it and disconnect peer that violates flow rules
219-
stream.window_ours = stream.window_ours.wrapping_sub(data.len() as u32);
219+
stream.window_ours =
220+
stream.window_ours.saturating_sub(data.len() as u32);
220221
}
221222
}
222223
YamuxFrameInner::WindowUpdate { difference } => {

p2p/src/service_impl/mio/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,11 @@ where
484484
if limit > self.recv_buf.len() {
485485
// TODO: upper bound? resize to `limit` or try to allocate some extra space too?
486486
self.recv_buf.resize(limit, 0);
487+
488+
openmina_core::warn!(
489+
openmina_core::log::system_time();
490+
summary = format!("Increasing buffer size to {}kb", limit / 1024)
491+
);
487492
}
488493

489494
let mut keep = false;

0 commit comments

Comments
 (0)