Skip to content
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: don't break RemoteStateActor if sending datagram fails
  • Loading branch information
Frando committed Nov 18, 2025
commit 7c11665bc75926e5ed9ac38fdb87d23a5219e055
37 changes: 13 additions & 24 deletions iroh/src/magicsock/remote_map/remote_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl RemoteStateActor {
}
}

pub(super) fn start(mut self) -> RemoteStateHandle {
pub(super) fn start(self) -> RemoteStateHandle {
let (tx, rx) = guarded_channel(16);
let me = self.local_endpoint_id;
let endpoint_id = self.endpoint_id;
Expand All @@ -193,19 +193,12 @@ impl RemoteStateActor {
// we don't explicitly set a span we get the spans from whatever call happens to
// first create the actor, which is often very confusing as it then keeps those
// spans for all logging of the actor.
let task = task::spawn(
async move {
if let Err(err) = self.run(rx).await {
error!("actor failed: {err:#}");
}
}
.instrument(info_span!(
parent: None,
"RemoteStateActor",
me = %me.fmt_short(),
remote = %endpoint_id.fmt_short(),
)),
);
let task = task::spawn(self.run(rx).instrument(info_span!(
parent: None,
"RemoteStateActor",
me = %me.fmt_short(),
remote = %endpoint_id.fmt_short(),
)));
RemoteStateHandle {
sender: tx,
_task: AbortOnDropHandle::new(task),
Expand All @@ -217,10 +210,7 @@ impl RemoteStateActor {
/// Note that the actor uses async handlers for tasks from the main loop. The actor is
/// not processing items from the inbox while waiting on any async calls. So some
/// discipline is needed to not turn pending for a long time.
async fn run(
&mut self,
mut inbox: GuardedReceiver<RemoteStateMessage>,
) -> n0_error::Result<()> {
async fn run(mut self, mut inbox: GuardedReceiver<RemoteStateMessage>) {
trace!("actor started");
let idle_timeout = MaybeFuture::None;
tokio::pin!(idle_timeout);
Expand All @@ -239,7 +229,7 @@ impl RemoteStateActor {
biased;
msg = inbox.recv() => {
match msg {
Some(msg) => self.handle_message(msg).await?,
Some(msg) => self.handle_message(msg).await,
None => break,
}
}
Expand Down Expand Up @@ -290,18 +280,19 @@ impl RemoteStateActor {
}
}
trace!("actor terminating");
Ok(())
}

/// Handles an actor message.
///
/// Error returns are fatal and kill the actor.
#[instrument(skip(self))]
async fn handle_message(&mut self, msg: RemoteStateMessage) -> n0_error::Result<()> {
async fn handle_message(&mut self, msg: RemoteStateMessage) {
// trace!("handling message");
match msg {
RemoteStateMessage::SendDatagram(transmit) => {
self.handle_msg_send_datagram(transmit).await?;
if let Err(err) = self.handle_msg_send_datagram(transmit).await {
warn!("failed to send datagram: {err:#}");
}
}
RemoteStateMessage::AddConnection(handle, tx) => {
self.handle_msg_add_connection(handle, tx).await;
Expand All @@ -325,15 +316,13 @@ impl RemoteStateActor {
self.handle_msg_latency(tx);
}
}
Ok(())
}

async fn send_datagram(
&self,
dst: transports::Addr,
owned_transmit: OwnedTransmit,
) -> n0_error::Result<()> {
debug!(?dst, "send datagram");
let transmit = transports::Transmit {
ecn: owned_transmit.ecn,
contents: owned_transmit.contents.as_ref(),
Expand Down
Loading