Skip to content

Commit

Permalink
fix: do not block on network change (#1885)
Browse files Browse the repository at this point in the history
There was a deadlock due to the usage of the inner actor message loop in
handling network changes, which would trigger a deadlock.

Additionally the following two fixes are included
- clearing endpoint state when connectivity is changed
- drop incoming messages when the magicsock is overloaded
  • Loading branch information
dignifiedquire committed Dec 15, 2023
1 parent 876a0f5 commit 54d5efc
Show file tree
Hide file tree
Showing 4 changed files with 298 additions and 27 deletions.
12 changes: 6 additions & 6 deletions iroh-net/src/derp/client_conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,14 @@ where
_ = done.cancelled() => {
trace!("cancelled");
// final flush
self.io.flush().await?;
self.io.flush().await.context("flush")?;
return Ok(());
}
read_res = self.io.next() => {
trace!("handle read");
match read_res {
Some(Ok(frame)) => {
self.handle_read(frame).await?;
self.handle_read(frame).await.context("handle_read")?;
}
Some(Err(err)) => {
return Err(err);
Expand All @@ -325,26 +325,26 @@ where
packet = self.send_queue.recv() => {
let packet = packet.context("Server.send_queue dropped")?;
trace!("send packet");
self.send_packet(packet).await?;
self.send_packet(packet).await.context("send packet")?;
// TODO: stats
// record `packet.enqueuedAt`
}
packet = self.disco_send_queue.recv() => {
let packet = packet.context("Server.disco_send_queue dropped")?;
trace!("send disco packet");
self.send_packet(packet).await?;
self.send_packet(packet).await.context("send packet")?;
// TODO: stats
// record `packet.enqueuedAt`
}
_ = keep_alive.tick() => {
trace!("keep alive");
self.send_keep_alive().await?;
self.send_keep_alive().await.context("send keep alive")?;
}
}
// TODO: golang batches as many writes as are in all the channels
// & then flushes when there is no more work to be done at the moment.
// refactor to get something similar
self.io.flush().await?;
self.io.flush().await.context("final flush")?;
}
}

Expand Down
Loading

0 comments on commit 54d5efc

Please sign in to comment.