diff --git a/README.md b/README.md index 3072a0f842..ae5f1589a9 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ let response = recv.read_to_end(1000).await?; assert_eq!(&response, b"Hello, world!"); // Close the endpoint and all its connections -endpoint.close().await?; +endpoint.close().await; ``` And on the accepting side: diff --git a/iroh-relay/src/server/clients.rs b/iroh-relay/src/server/clients.rs index 2164f149d4..2f60d7b078 100644 --- a/iroh-relay/src/server/clients.rs +++ b/iroh-relay/src/server/clients.rs @@ -71,7 +71,7 @@ impl Clients { /// peer is gone from the network. /// /// Must be passed a matching connection_id. - pub(super) async fn unregister<'a>(&self, connection_id: u64, node_id: NodeId) { + pub(super) async fn unregister(&self, connection_id: u64, node_id: NodeId) { trace!( node_id = node_id.fmt_short(), connection_id, diff --git a/iroh/bench/src/lib.rs b/iroh/bench/src/lib.rs index 5db1af7e04..a82e0cfa32 100644 --- a/iroh/bench/src/lib.rs +++ b/iroh/bench/src/lib.rs @@ -83,17 +83,16 @@ pub enum EndpointSelector { } impl EndpointSelector { - pub async fn close(self) -> Result<()> { + pub async fn close(self) { match self { EndpointSelector::Iroh(endpoint) => { - endpoint.close().await?; + endpoint.close().await; } #[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))] EndpointSelector::Quinn(endpoint) => { endpoint.close(0u32.into(), b""); } } - Ok(()) } } @@ -255,7 +254,7 @@ pub async fn client_handler( // to `Arc`ing them connection.close(0u32, b"Benchmark done"); - endpoint.close().await?; + endpoint.close().await; if opt.stats { println!("\nClient connection stats:\n{:#?}", connection.stats()); diff --git a/iroh/examples/connect.rs b/iroh/examples/connect.rs index 5187c02a1d..e762e2a665 100644 --- a/iroh/examples/connect.rs +++ b/iroh/examples/connect.rs @@ -91,6 +91,6 @@ async fn main() -> anyhow::Result<()> { // We received the last message: close all connections and allow for the close // message to be sent. - endpoint.close().await?; + endpoint.close().await; Ok(()) } diff --git a/iroh/examples/transfer.rs b/iroh/examples/transfer.rs index e16315351a..31d64ed8f3 100644 --- a/iroh/examples/transfer.rs +++ b/iroh/examples/transfer.rs @@ -218,13 +218,7 @@ async fn fetch(ticket: &str, relay_url: Option, relay_only: bool) -> any // We received the last message: close all connections and allow for the close // message to be sent. - tokio::time::timeout(Duration::from_secs(3), async move { - let res = endpoint.close().await; - if res.is_err() { - println!("failed to close connection: {res:#?}"); - } - }) - .await?; + tokio::time::timeout(Duration::from_secs(3), endpoint.close()).await?; let duration = start.elapsed(); println!( diff --git a/iroh/src/endpoint.rs b/iroh/src/endpoint.rs index fe03fd3f35..781514cc0d 100644 --- a/iroh/src/endpoint.rs +++ b/iroh/src/endpoint.rs @@ -972,12 +972,9 @@ impl Endpoint { /// Be aware however that the underlying UDP sockets are only closed /// on [`Drop`], bearing in mind the [`Endpoint`] is only dropped once all the clones /// are dropped. - /// - /// Returns an error if closing the magic socket failed. - /// TODO: Document error cases. - pub async fn close(&self) -> Result<()> { + pub async fn close(&self) { if self.is_closed() { - return Ok(()); + return; } tracing::debug!("Closing connections"); @@ -985,8 +982,7 @@ impl Endpoint { self.endpoint.wait_idle().await; tracing::debug!("Connections closed"); - self.msock.close().await?; - Ok(()) + self.msock.close().await; } /// Check if this endpoint is still alive, or already closed. @@ -1594,7 +1590,7 @@ mod tests { info!("closing endpoint"); // close the endpoint and restart it - endpoint.close().await.unwrap(); + endpoint.close().await; info!("restarting endpoint"); // now restart it and check the addressing info of the peer @@ -1693,7 +1689,7 @@ mod tests { send.stopped().await.unwrap(); recv.read_to_end(0).await.unwrap(); info!("client finished"); - ep.close().await.unwrap(); + ep.close().await; info!("client closed"); } .instrument(error_span!("client", %i)) diff --git a/iroh/src/lib.rs b/iroh/src/lib.rs index 988b7697a4..b844020fc0 100644 --- a/iroh/src/lib.rs +++ b/iroh/src/lib.rs @@ -173,7 +173,7 @@ //! //! // Gracefully close the connection and endpoint. //! conn.close(1u8.into(), b"done"); -//! ep.close().await?; +//! ep.close().await; //! println!("Client closed"); //! Ok(()) //! } @@ -202,7 +202,7 @@ //! //! // Wait for the client to close the connection and gracefully close the endpoint. //! conn.closed().await; -//! ep.close().await?; +//! ep.close().await; //! Ok(()) //! } //! ``` diff --git a/iroh/src/magicsock.rs b/iroh/src/magicsock.rs index e32d16ad65..0bef9bd7b7 100644 --- a/iroh/src/magicsock.rs +++ b/iroh/src/magicsock.rs @@ -1654,12 +1654,18 @@ impl Handle { /// Polling the socket ([`AsyncUdpSocket::poll_recv`]) will return [`Poll::Pending`] /// indefinitely after this call. #[instrument(skip_all, fields(me = %self.msock.me))] - pub(crate) async fn close(&self) -> Result<()> { + pub(crate) async fn close(&self) { if self.msock.is_closed() { - return Ok(()); + return; } self.msock.closing.store(true, Ordering::Relaxed); - self.msock.actor_sender.send(ActorMessage::Shutdown).await?; + // If this fails, then there's no receiver listening for shutdown messages, + // so nothing to shut down anyways. + self.msock + .actor_sender + .send(ActorMessage::Shutdown) + .await + .ok(); self.msock.closed.store(true, Ordering::SeqCst); let mut tasks = self.actor_tasks.lock().await; @@ -1681,8 +1687,6 @@ impl Handle { debug!("aborting remaining {}/3 tasks", tasks.len()); tasks.shutdown().await; } - - Ok(()) } } @@ -3408,8 +3412,8 @@ mod tests { println!("closing endpoints"); let msock1 = m1.endpoint.magic_sock(); let msock2 = m2.endpoint.magic_sock(); - m1.endpoint.close().await?; - m2.endpoint.close().await?; + m1.endpoint.close().await; + m2.endpoint.close().await; assert!(msock1.msock.is_closed()); assert!(msock2.msock.is_closed());