Skip to content

Commit db80bbf

Browse files
authored
fix(upnp): ignore oneshot sender error when receiver is dropped
Resolves #5077. Pull-Request: #5096.
1 parent 96c4055 commit db80bbf

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ libp2p-swarm-test = { version = "0.3.0", path = "swarm-test" }
108108
libp2p-tcp = { version = "0.41.0", path = "transports/tcp" }
109109
libp2p-tls = { version = "0.3.0", path = "transports/tls" }
110110
libp2p-uds = { version = "0.40.0", path = "transports/uds" }
111-
libp2p-upnp = { version = "0.2.0", path = "protocols/upnp" }
111+
libp2p-upnp = { version = "0.2.1", path = "protocols/upnp" }
112112
libp2p-webrtc = { version = "0.7.0-alpha", path = "transports/webrtc" }
113113
libp2p-webrtc-utils = { version = "0.2.0", path = "misc/webrtc-utils" }
114114
libp2p-webrtc-websys = { version = "0.3.0-alpha", path = "transports/webrtc-websys" }

protocols/upnp/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.1
2+
- Fix a panic caused when dropping `upnp::Behaviour` such as when used together with `Toggle`.
3+
See [PR 5096](https://github.com/libp2p/rust-libp2p/pull/5096).
4+
15
## 0.2.0
26

37

protocols/upnp/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "libp2p-upnp"
33
edition = "2021"
44
rust-version = "1.60.0"
55
description = "UPnP support for libp2p transports"
6-
version = "0.2.0"
6+
version = "0.2.1"
77
license = "MIT"
88
repository = "https://github.com/libp2p/rust-libp2p"
99
keywords = ["peer-to-peer", "libp2p", "networking"]

protocols/upnp/src/tokio.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,30 +100,30 @@ pub(crate) fn search_gateway() -> oneshot::Receiver<Result<Gateway, Box<dyn Erro
100100
let gateway = match igd_next::aio::tokio::search_gateway(SearchOptions::default()).await {
101101
Ok(gateway) => gateway,
102102
Err(err) => {
103-
search_result_sender
104-
.send(Err(err.into()))
105-
.expect("receiver shouldn't have been dropped");
103+
let _ = search_result_sender.send(Err(err.into()));
106104
return;
107105
}
108106
};
109107

110108
let external_addr = match gateway.get_external_ip().await {
111109
Ok(addr) => addr,
112110
Err(err) => {
113-
search_result_sender
114-
.send(Err(err.into()))
115-
.expect("receiver shouldn't have been dropped");
111+
let _ = search_result_sender.send(Err(err.into()));
116112
return;
117113
}
118114
};
119115

120-
search_result_sender
116+
// Check if receiver dropped.
117+
if search_result_sender
121118
.send(Ok(Gateway {
122119
sender: events_sender,
123120
receiver: events_queue,
124121
external_addr,
125122
}))
126-
.expect("receiver shouldn't have been dropped");
123+
.is_err()
124+
{
125+
return;
126+
}
127127

128128
loop {
129129
// The task sender has dropped so we can return.

0 commit comments

Comments
 (0)