From a424310d6081c37c2f00e33f5f937fc307c71d3b Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 24 May 2023 08:25:05 +0200 Subject: [PATCH] fix(swarm): poll handler after injecting `LocalProtocolsChange` event Previously, we would not call the handler upon injecting `ConnectionEvent::LocalProtocolsChange`. This would prevent protocols from being able to react to this change and e.g. issue events or open streams. Pull-Request: #3979. --- swarm/src/connection.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index eab521593ac..b8f3b50338b 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -425,12 +425,17 @@ where } let new_protocols = gather_supported_protocols(handler); + let changes = ProtocolsChange::from_full_sets(supported_protocols, &new_protocols); - for change in ProtocolsChange::from_full_sets(supported_protocols, &new_protocols) { - handler.on_connection_event(ConnectionEvent::LocalProtocolsChange(change)); - } + if !changes.is_empty() { + for change in changes { + handler.on_connection_event(ConnectionEvent::LocalProtocolsChange(change)); + } - *supported_protocols = new_protocols; + *supported_protocols = new_protocols; + + continue; // Go back to the top, handler can potentially make progress again. + } return Poll::Pending; // Nothing can make progress, return `Pending`. }