Comments (2)
Hi Darius, and thanks for reporting this, nice catch.
The proposed solution is very elegant, the only downside would be that if someone can still poll the behaviour manually and then drop it right after triggering the panics. We could just address the panics themselves:
diff --git a/protocols/upnp/src/tokio.rs b/protocols/upnp/src/tokio.rs
index c6a40182b..9c8b2cafe 100644
--- a/protocols/upnp/src/tokio.rs
+++ b/protocols/upnp/src/tokio.rs
@@ -100,9 +100,7 @@ pub(crate) fn search_gateway() -> oneshot::Receiver<Result<Gateway, Box<dyn Erro
let gateway = match igd_next::aio::tokio::search_gateway(SearchOptions::default()).await {
Ok(gateway) => gateway,
Err(err) => {
- search_result_sender
- .send(Err(err.into()))
- .expect("receiver shouldn't have been dropped");
+ let _ = search_result_sender.send(Err(err.into()));
return;
}
};
@@ -110,20 +108,22 @@ pub(crate) fn search_gateway() -> oneshot::Receiver<Result<Gateway, Box<dyn Erro
let external_addr = match gateway.get_external_ip().await {
Ok(addr) => addr,
Err(err) => {
- search_result_sender
- .send(Err(err.into()))
- .expect("receiver shouldn't have been dropped");
+ let _ = search_result_sender.send(Err(err.into()));
return;
}
};
- search_result_sender
+ // Check if receiver dropped.
+ if search_result_sender
.send(Ok(Gateway {
sender: events_sender,
receiver: events_queue,
external_addr,
}))
- .expect("receiver shouldn't have been dropped");
+ .is_err()
+ {
+ return;
+ }
loop {
// The task sender has dropped so we can return.
wdyt?
from rust-libp2p.
Hi Darius, and thanks for reporting this, nice catch. The proposed solution is very elegant, the only downside would be that if someone can still poll the behaviour manually and then drop it right after triggering the panics. We could just address the panics themselves:
diff --git a/protocols/upnp/src/tokio.rs b/protocols/upnp/src/tokio.rs index c6a40182b..9c8b2cafe 100644 --- a/protocols/upnp/src/tokio.rs +++ b/protocols/upnp/src/tokio.rs @@ -100,9 +100,7 @@ pub(crate) fn search_gateway() -> oneshot::Receiver<Result<Gateway, Box<dyn Erro let gateway = match igd_next::aio::tokio::search_gateway(SearchOptions::default()).await { Ok(gateway) => gateway, Err(err) => { - search_result_sender - .send(Err(err.into())) - .expect("receiver shouldn't have been dropped"); + let _ = search_result_sender.send(Err(err.into())); return; } }; @@ -110,20 +108,22 @@ pub(crate) fn search_gateway() -> oneshot::Receiver<Result<Gateway, Box<dyn Erro let external_addr = match gateway.get_external_ip().await { Ok(addr) => addr, Err(err) => { - search_result_sender - .send(Err(err.into())) - .expect("receiver shouldn't have been dropped"); + let _ = search_result_sender.send(Err(err.into())); return; } }; - search_result_sender + // Check if receiver dropped. + if search_result_sender .send(Ok(Gateway { sender: events_sender, receiver: events_queue, external_addr, })) - .expect("receiver shouldn't have been dropped"); + .is_err() + { + return; + } loop { // The task sender has dropped so we can return.wdyt?
Looks good to me :) Although i dont know of a case where one would poll it manually, however I do like the idea of addressing it directly
from rust-libp2p.
Related Issues (20)
- feat(ping): make the ignoring of the first error configurable
- kad: remove default IPFS DHT protocol name HOT 3
- File-Sharing example silently fails and or panics when trying to send a file too big. HOT 6
- `websocket_websys` does not work in NodeJS environments HOT 7
- Re-export multihash from libp2p-identity with peerid feature HOT 3
- Autonat: Uvi PermissionDenied len > max when encoding error HOT 1
- Peer closes connection before other peer has read all the data HOT 6
- There seems to be bugs on the Chat example HOT 6
- Finer-grained multistream-select upgrade protocol version selection HOT 5
- Persistent peer identity during restart make it unable to publish message with gossipsub HOT 15
- kad: emit `ToSwarm::NewExternalAddrOfPeer` HOT 6
- mDNS: emit `ToSwarm::NewExternalAddrOfPeer` HOT 7
- rendezvous: emit `ToSwarm::NewExternalAddrOfPeer` HOT 4
- libp2p-webrtc: compiling fails with latest version 0.53.2 with feature flag noise HOT 1
- Opening a subsequent stream on the same protocol with the same peer fails HOT 1
- Quic `Protocol not available` error when running relay server example HOT 7
- link error on ios: undefined symbols _kSCNetworkInterfaceTypeIrDA HOT 9
- Using VecDeque for pending events in various protocols causes task to not wake when a new event is added HOT 11
- Second node not building. Error: InvalidMultiaddr HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-libp2p.