Skip to content

Commit

Permalink
fix(upnp): don't panic when gateway is dropped
Browse files Browse the repository at this point in the history
There seems to be a situation when the `Behaviour` and therefore it's `Gateway` is dropped leaving the `tokio` loop to panic.  It has been reported on  sigp/lighthouse#5498, this attempts to fix it.
Cc @dariusc93 can you review this please Darius? Thanks!

Pull-Request: #5273.
  • Loading branch information
jxs authored Mar 29, 2024
1 parent 098dd02 commit a94e943
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ libp2p-swarm-test = { version = "0.3.0", path = "swarm-test" }
libp2p-tcp = { version = "0.41.0", path = "transports/tcp" }
libp2p-tls = { version = "0.3.0", path = "transports/tls" }
libp2p-uds = { version = "0.40.0", path = "transports/uds" }
libp2p-upnp = { version = "0.2.1", path = "protocols/upnp" }
libp2p-upnp = { version = "0.2.2", path = "protocols/upnp" }
libp2p-webrtc = { version = "0.7.1-alpha", path = "transports/webrtc" }
libp2p-webrtc-utils = { version = "0.2.0", path = "misc/webrtc-utils" }
libp2p-webrtc-websys = { version = "0.3.0-alpha", path = "transports/webrtc-websys" }
Expand Down
5 changes: 5 additions & 0 deletions protocols/upnp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.2.2
- Fix a panic caused when `upnp::Gateway` is dropped and its events queue receiver is no longer
available.
See [PR 5273](https://github.com/libp2p/rust-libp2p/pull/5273).

## 0.2.1
- Fix a panic caused when dropping `upnp::Behaviour` such as when used together with `Toggle`.
See [PR 5096](https://github.com/libp2p/rust-libp2p/pull/5096).
Expand Down
2 changes: 1 addition & 1 deletion protocols/upnp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-upnp"
edition = "2021"
rust-version = "1.60.0"
description = "UPnP support for libp2p transports"
version = "0.2.1"
version = "0.2.2"
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
keywords = ["peer-to-peer", "libp2p", "networking"]
Expand Down
8 changes: 4 additions & 4 deletions protocols/upnp/src/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ pub(crate) fn search_gateway() -> oneshot::Receiver<Result<Gateway, Box<dyn Erro
}
}
};
task_sender
.send(event)
.await
.expect("receiver should be available");
// Gateway was dropped.
if task_sender.send(event).await.is_err() {
return;
}
}
});

Expand Down

0 comments on commit a94e943

Please sign in to comment.