Content-Length: 8574 | pFad | http://github.com/paritytech/litep2p/pull/296.patch
67943219
From 7683f90184a09a0a8f94f25ff7550291d5cd8219 Mon Sep 17 00:00:00 2001
From: Alexandru Vasile
Date: Mon, 2 Dec 2024 11:30:57 +0200
Subject: [PATCH 1/3] notification: Fix memory leak of pending substreams
Signed-off-by: Alexandru Vasile
---
src/protocol/notification/mod.rs | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/protocol/notification/mod.rs b/src/protocol/notification/mod.rs
index 42063081..34136fb0 100644
--- a/src/protocol/notification/mod.rs
+++ b/src/protocol/notification/mod.rs
@@ -435,18 +435,30 @@ impl NotificationProtocol {
},
);
}
+ (OutboundState::OutboundInitiated { substream }, _) => {
+ tracing::debug!(
+ target: LOG_TARGET,
+ ?peer,
+ protocol = %self.protocol,
+ "connection closed outbound substream initiated ",
+ );
+ // We need to remove this state to avoid a memory leak.
+ self.pending_outbound.remove(&substream);
+
+ self.event_handle
+ .report_notification_stream_open_failure(
+ peer,
+ NotificationError::Rejected,
+ )
+ .await;
+ }
// user either initiated an outbound substream or an outbound substream was
// opened/being opened as a result of an accepted inbound substream but was not
// yet fully open
//
// to have consistent state tracking in the user protocol, substream rejection
// must be reported to the user
- (
- OutboundState::OutboundInitiated { .. }
- | OutboundState::Negotiating
- | OutboundState::Open { .. },
- _,
- ) => {
+ (OutboundState::Negotiating | OutboundState::Open { .. }, _) => {
tracing::debug!(
target: LOG_TARGET,
?peer,
From a756ebf07a399a20fa5c239e981d91dd8473cf11 Mon Sep 17 00:00:00 2001
From: Alexandru Vasile
Date: Tue, 3 Dec 2024 09:38:33 +0000
Subject: [PATCH 2/3] notification: Update comments
Signed-off-by: Alexandru Vasile
---
src/protocol/notification/mod.rs | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/protocol/notification/mod.rs b/src/protocol/notification/mod.rs
index 34136fb0..e22b29d5 100644
--- a/src/protocol/notification/mod.rs
+++ b/src/protocol/notification/mod.rs
@@ -435,6 +435,10 @@ impl NotificationProtocol {
},
);
}
+ // User initiated an outbound substream but the connection was closed before the
+ // substream was fully open.
+ // To have consistent state tracking in the user protocol, substream rejection
+ // must be reported to the user.
(OutboundState::OutboundInitiated { substream }, _) => {
tracing::debug!(
target: LOG_TARGET,
@@ -452,12 +456,11 @@ impl NotificationProtocol {
)
.await;
}
- // user either initiated an outbound substream or an outbound substream was
- // opened/being opened as a result of an accepted inbound substream but was not
- // yet fully open
+ // An outbound substream was opened/being opened as a result of an accepted
+ // inbound substream but was not yet fully open.
//
- // to have consistent state tracking in the user protocol, substream rejection
- // must be reported to the user
+ // To have consistent state tracking in the user protocol, substream rejection
+ // must be reported to the user.
(OutboundState::Negotiating | OutboundState::Open { .. }, _) => {
tracing::debug!(
target: LOG_TARGET,
From bf8e695637f3e4ff990d8202f612b437c1d55e37 Mon Sep 17 00:00:00 2001
From: Alexandru Vasile
Date: Tue, 3 Dec 2024 13:29:34 +0000
Subject: [PATCH 3/3] notification: Fix leak at the beginning of the method
Signed-off-by: Alexandru Vasile
---
src/protocol/notification/mod.rs | 41 +++++++++++---------------------
1 file changed, 14 insertions(+), 27 deletions(-)
diff --git a/src/protocol/notification/mod.rs b/src/protocol/notification/mod.rs
index e22b29d5..33108d3f 100644
--- a/src/protocol/notification/mod.rs
+++ b/src/protocol/notification/mod.rs
@@ -258,7 +258,7 @@ pub(crate) struct NotificationProtocol {
//github.com/ Connected peers.
peers: HashMap,
- //github.com/ Pending outboudn substreams.
+ //github.com/ Pending outbound substreams.
pending_outbound: HashMap,
//github.com/ Handshaking service which reads and writes the handshakes to inbound
@@ -384,6 +384,8 @@ impl NotificationProtocol {
async fn on_connection_closed(&mut self, peer: PeerId) -> crate::Result<()> {
tracing::trace!(target: LOG_TARGET, ?peer, protocol = %self.protocol, "connection closed");
+ self.pending_outbound.retain(|_, p| p != &peer);
+
let Some(context) = self.peers.remove(&peer) else {
tracing::error!(
target: LOG_TARGET,
@@ -435,33 +437,18 @@ impl NotificationProtocol {
},
);
}
- // User initiated an outbound substream but the connection was closed before the
- // substream was fully open.
- // To have consistent state tracking in the user protocol, substream rejection
- // must be reported to the user.
- (OutboundState::OutboundInitiated { substream }, _) => {
- tracing::debug!(
- target: LOG_TARGET,
- ?peer,
- protocol = %self.protocol,
- "connection closed outbound substream initiated ",
- );
- // We need to remove this state to avoid a memory leak.
- self.pending_outbound.remove(&substream);
-
- self.event_handle
- .report_notification_stream_open_failure(
- peer,
- NotificationError::Rejected,
- )
- .await;
- }
- // An outbound substream was opened/being opened as a result of an accepted
- // inbound substream but was not yet fully open.
+ // user either initiated an outbound substream or an outbound substream was
+ // opened/being opened as a result of an accepted inbound substream but was not
+ // yet fully open
//
- // To have consistent state tracking in the user protocol, substream rejection
- // must be reported to the user.
- (OutboundState::Negotiating | OutboundState::Open { .. }, _) => {
+ // to have consistent state tracking in the user protocol, substream rejection
+ // must be reported to the user
+ (
+ OutboundState::OutboundInitiated { .. }
+ | OutboundState::Negotiating
+ | OutboundState::Open { .. },
+ _,
+ ) => {
tracing::debug!(
target: LOG_TARGET,
?peer,
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/paritytech/litep2p/pull/296.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy