diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index 69f26e447b8..e86afde808e 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -7,9 +7,13 @@ - Reduce the initial delay before running the identify protocol to 0 and make the option deprecated. See [PR 3545]. +- Fix aborting the answering of an identify request in rare situations. + See [PR 3876]. + [PR 3698]: https://github.com/libp2p/rust-libp2p/pull/3698 [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 [PR 3545]: https://github.com/libp2p/rust-libp2p/pull/3545 +[PR 3876]: https://github.com/libp2p/rust-libp2p/pull/3876 ## 0.42.2 diff --git a/protocols/identify/src/handler.rs b/protocols/identify/src/handler.rs index 0c72635dcb6..96f15924ee7 100644 --- a/protocols/identify/src/handler.rs +++ b/protocols/identify/src/handler.rs @@ -64,9 +64,6 @@ pub struct Handler { /// Future that fires when we need to identify the node again. trigger_next_identify: Delay, - /// Whether the handler should keep the connection alive. - keep_alive: KeepAlive, - /// The interval of `trigger_next_identify`, i.e. the recurrent delay. interval: Duration, @@ -132,7 +129,6 @@ impl Handler { reply_streams: VecDeque::new(), pending_replies: FuturesUnordered::new(), trigger_next_identify: Delay::new(initial_delay), - keep_alive: KeepAlive::Yes, interval, public_key, protocol_version, @@ -190,7 +186,6 @@ impl Handler { .push(ConnectionHandlerEvent::Custom(Event::Identified( remote_info, ))); - self.keep_alive = KeepAlive::No; } future::Either::Right(()) => self .events @@ -210,7 +205,6 @@ impl Handler { .push(ConnectionHandlerEvent::Custom(Event::IdentificationError( err, ))); - self.keep_alive = KeepAlive::No; self.trigger_next_identify.reset(self.interval); } } @@ -268,7 +262,19 @@ impl ConnectionHandler for Handler { } fn connection_keep_alive(&self) -> KeepAlive { - self.keep_alive + if self.inbound_identify_push.is_some() { + return KeepAlive::Yes; + } + + if !self.pending_replies.is_empty() { + return KeepAlive::Yes; + } + + if !self.reply_streams.is_empty() { + return KeepAlive::Yes; + } + + KeepAlive::No } fn poll(