fix(swarm): gracefully disable oneshot handler on dial upgrade errors

Resolves https://github.com/libp2p/rust-libp2p/issues/3269.

Pull-Request: #3577.
This commit is contained in:
Victor Ermolaev
2023-03-13 21:37:59 +01:00
committed by GitHub
parent 2ec5402474
commit 2a18f7a5f0
3 changed files with 11 additions and 4 deletions

View File

@ -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
@ -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

View File

@ -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 {
@ -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)
}
}
}
}
@ -481,7 +484,7 @@ where
match self {
ConnectionHandlerUpgrErr::Timeout => None,
ConnectionHandlerUpgrErr::Timer => None,
ConnectionHandlerUpgrErr::Upgrade(err) => Some(err),
ConnectionHandlerUpgrErr::Upgrade(_) => None,
}
}
}

View File

@ -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(_) => {}