Skip to content

Commit

Permalink
fix(swarm): gracefully disable oneshot handler on dial upgrade errors
Browse files Browse the repository at this point in the history
Resolves #3269.

Pull-Request: #3577.
  • Loading branch information
vnermolaev authored Mar 13, 2023
1 parent 2ec5402 commit 2a18f7a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions swarm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
- Deprecate methods `Swarm::with_executor`, `Swarm::with_*_executor`, `Swarm::without_executor`.
Introduce similar methods in `SwarmBuilder`. See [PR 3588].

- Gracefully disable oneshot handler on dial upgrade errors. See [PR 3577].

[PR 3364]: https://github.com/libp2p/rust-libp2p/pull/3364
[PR 3170]: https://github.com/libp2p/rust-libp2p/pull/3170
[PR 3134]: https://github.com/libp2p/rust-libp2p/pull/3134
Expand All @@ -106,6 +108,7 @@
[PR 3254]: https://github.com/libp2p/rust-libp2p/pull/3254
[PR 3497]: https://github.com/libp2p/rust-libp2p/pull/3497
[PR 3588]: https://github.com/libp2p/rust-libp2p/pull/3588
[PR 3577]: https://github.com/libp2p/rust-libp2p/pull/3577

# 0.41.1

Expand Down
9 changes: 6 additions & 3 deletions swarm/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ impl<TUpgrErr> ConnectionHandlerUpgrErr<TUpgrErr> {

impl<TUpgrErr> fmt::Display for ConnectionHandlerUpgrErr<TUpgrErr>
where
TUpgrErr: fmt::Display,
TUpgrErr: error::Error + 'static,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand All @@ -468,7 +468,10 @@ where
ConnectionHandlerUpgrErr::Timer => {
write!(f, "Timer error while opening a substream")
}
ConnectionHandlerUpgrErr::Upgrade(err) => write!(f, "{err}"),
ConnectionHandlerUpgrErr::Upgrade(err) => {
write!(f, "Upgrade: ")?;
crate::print_error_chain(f, err)
}
}
}
}
Expand All @@ -481,7 +484,7 @@ where
match self {
ConnectionHandlerUpgrErr::Timeout => None,
ConnectionHandlerUpgrErr::Timer => None,
ConnectionHandlerUpgrErr::Upgrade(err) => Some(err),
ConnectionHandlerUpgrErr::Upgrade(_) => None,
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion swarm/src/handler/one_shot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ where
}
ConnectionEvent::DialUpgradeError(DialUpgradeError { error, .. }) => {
if self.pending_error.is_none() {
self.pending_error = Some(error);
log::debug!("DialUpgradeError: {error}");
self.keep_alive = KeepAlive::No;
}
}
ConnectionEvent::AddressChange(_) | ConnectionEvent::ListenUpgradeError(_) => {}
Expand Down

0 comments on commit 2a18f7a

Please sign in to comment.