Skip to content

Commit

Permalink
fix(gossipsub): gracefully disable handler on stream errors
Browse files Browse the repository at this point in the history
Previously, we closed the entire connection upon receiving too many upgrade errors. This is unnecessarily aggressive. For example, an upgrade error may be caused by the remote dropping a stream during the initial handshake which is completely isolated from other protocols running on the same connection.

Instead of closing the connection, set `KeepAlive::No`.

Related: #3591.
Resolves: #3690.

Pull-Request: #3625.
  • Loading branch information
vnermolaev authored Apr 14, 2023
1 parent 058c2d8 commit 96288b8
Show file tree
Hide file tree
Showing 11 changed files with 301 additions and 278 deletions.
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions protocols/gossipsub/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

- Fix erroneously duplicate message IDs. See [PR 3716].

- Gracefully disable handler on stream errors. Deprecate a few variants of `HandlerError`.
See [PR 3625].

[PR 3716]: https://github.com/libp2p/rust-libp2p/pull/3716
[PR 3625]: https://github.com/libp2p/rust-libp2p/pull/3325

## 0.44.2

Expand Down
4 changes: 3 additions & 1 deletion protocols/gossipsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]

[dependencies]
libp2p-swarm = { version = "0.42.1", path = "../../swarm" }
either = "1.5"
libp2p-swarm = { version = "0.42.2", path = "../../swarm" }
libp2p-core = { version = "0.39.0", path = "../../core" }
libp2p-identity = { version = "0.1.2", path = "../../identity" }
bytes = "1.4"
Expand All @@ -33,6 +34,7 @@ serde = { version = "1", optional = true, features = ["derive"] }
thiserror = "1.0"
wasm-timer = "0.2.5"
instant = "0.1.11"
void = "1.0.2"
# Metrics dependencies
prometheus-client = "0.19.0"

Expand Down
10 changes: 2 additions & 8 deletions protocols/gossipsub/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,10 @@ pub type PublishError = crate::error_priv::PublishError;
)]
pub type SubscriptionError = crate::error_priv::SubscriptionError;

#[deprecated(
since = "0.44.0",
note = "Use re-exports that omit `Gossipsub` prefix, i.e. `libp2p::gossipsub::HandlerError"
)]
#[deprecated(note = "This error will no longer be emitted")]
pub type GossipsubHandlerError = crate::error_priv::HandlerError;

#[deprecated(
since = "0.44.0",
note = "Use `libp2p::gossipsub::HandlerError` instead, as the `error` module will become crate-private in the future."
)]
#[deprecated(note = "This error will no longer be emitted")]
pub type HandlerError = crate::error_priv::HandlerError;

#[deprecated(
Expand Down
6 changes: 0 additions & 6 deletions protocols/gossipsub/src/error_priv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,6 @@ impl std::fmt::Display for ValidationError {

impl std::error::Error for ValidationError {}

impl From<std::io::Error> for HandlerError {
fn from(error: std::io::Error) -> HandlerError {
HandlerError::Codec(quick_protobuf_codec::Error::from(error))
}
}

impl From<std::io::Error> for PublishError {
fn from(error: std::io::Error) -> PublishError {
PublishError::TransformFailed(error)
Expand Down
Loading

0 comments on commit 96288b8

Please sign in to comment.