-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
upnp: Panics when defaulting for Toggle #5077
Comments
Hi Darius, and thanks for reporting this, nice catch. 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 |
Summary
When using
Toggle
for upnp behaviour, it panics due to the oneshot receiver dropping. This happens when performing something along the lines ofwhich would be drop. While the solution to get around this would to maybe use
Toggle::from(protocols.upnp.then(libp2p::upnp::tokio::Behaviour::default))
to have it lazily evaluated or expand on the check, I do feel this is a bad behaviour for it to be doing this on default while usingthen_some
Expected behavior
Not to panic when behaviour is disabled
Actual behavior
Panics due to a dropped oneshot receiver
Relevant log output
Possible Solution
GatewayState::Pending
(as an example) and change it toGatewayState::Searching
on the first poll, which would prevent the panic that occurs due to the oneshot receiver dropping. The following should sufficeVersion
0.53.2
Would you like to work on fixing this bug ?
Yes
The text was updated successfully, but these errors were encountered: