Skip to content

Commit af19055

Browse files
authored
notification: Fix memory leak of pending substreams (#296)
This PR fixes a subtle memory leak that can happen in the following edge-case situation: - connection is established and substream outbound is initiated with remote peer - the substream ID is tracked until the substream either completes successfully or fails - the connection is closed soon after, leading to no substream events ever being generated For this edge-cases, we need to remove the tracking of the substream ID when the connection is reported as closed. This has been detected after running a node for more than 2 days with the following generic metrics PR: - #294 Closes: #295 cc @paritytech/networking --------- Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
1 parent 7612ec9 commit af19055

File tree

1 file changed

+3
-1
lines changed
  • src/protocol/notification

1 file changed

+3
-1
lines changed

src/protocol/notification/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ pub(crate) struct NotificationProtocol {
258258
/// Connected peers.
259259
peers: HashMap<PeerId, PeerContext>,
260260

261-
/// Pending outboudn substreams.
261+
/// Pending outbound substreams.
262262
pending_outbound: HashMap<SubstreamId, PeerId>,
263263

264264
/// Handshaking service which reads and writes the handshakes to inbound
@@ -384,6 +384,8 @@ impl NotificationProtocol {
384384
async fn on_connection_closed(&mut self, peer: PeerId) -> crate::Result<()> {
385385
tracing::trace!(target: LOG_TARGET, ?peer, protocol = %self.protocol, "connection closed");
386386

387+
self.pending_outbound.retain(|_, p| p != &peer);
388+
387389
let Some(context) = self.peers.remove(&peer) else {
388390
tracing::error!(
389391
target: LOG_TARGET,

0 commit comments

Comments
 (0)