Skip to content
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

mdns/fix: Failed to register opened substream #301

Merged
merged 6 commits into from
Dec 12, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/protocol/mdns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

//! [Multicast DNS](https://en.wikipedia.org/wiki/Multicast_DNS) implementation.

use crate::{error::Error, transport::manager::TransportManagerHandle, DEFAULT_CHANNEL_SIZE};
use crate::{transport::manager::TransportManagerHandle, DEFAULT_CHANNEL_SIZE};

use futures::Stream;
use multiaddr::Multiaddr;
Expand Down Expand Up @@ -276,13 +276,14 @@ impl Mdns {
}

/// Event loop for [`Mdns`].
pub(crate) async fn start(mut self) -> crate::Result<()> {
pub(crate) async fn start(mut self) {
tracing::debug!(target: LOG_TARGET, "starting mdns event loop");

// before starting the loop, make an initial query to the network
//
// bail early if the socket is not working
self.on_outbound_request().await?;
// Before starting the loop, make an initial query to the network
if let Err(error) = self.on_outbound_request().await {
tracing::error!(target: LOG_TARGET, ?error, "Failed to send initial mdns query. MDNS entering failure mode");
futures::future::pending::<()>().await;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically execution would be stuck here forever, right? Is it a problem that self.socket will never be polled then below?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would tokio::time::Interval work here? It fires immediately the first time, so there will be no need to send the first outbound request manually.

The caveat is to use Delay MissedTickBehavior, otherwise we might end up bursting many packets if for some reason other branches of select! take too long.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep indeed, have ended up using tokio::time::Interval here 🙏

}

loop {
tokio::select! {
Expand All @@ -291,7 +292,6 @@ impl Mdns {

if let Err(error) = self.on_outbound_request().await {
tracing::error!(target: LOG_TARGET, ?error, "failed to send mdns query");
return Err(error);
}
}
result = self.socket.recv_from(&mut self.receive_buffer) => match result {
Expand All @@ -308,9 +308,11 @@ impl Mdns {
}
}
false => if let Some(response) = self.on_inbound_request(packet) {
self.socket
if let Err(error) = self.socket
.send_to(&response, (IPV4_MULTICAST_ADDRESS, IPV4_MULTICAST_PORT))
.await?;
.await {
tracing::error!(target: LOG_TARGET, ?error, "failed to send mdns response");
}
}
}
Err(error) => tracing::debug!(
Expand All @@ -323,7 +325,6 @@ impl Mdns {
}
Err(error) => {
tracing::error!(target: LOG_TARGET, ?error, "failed to read from socket");
return Err(Error::from(error));
}
},
}
Expand Down
Loading