Skip to content

Commit 4011d3b

Browse files
authored
fix: Await async_channel::Sender::send (#662)
This makes sure to await the future from async_channel::Sender::send. When not awaiting this only makes a struct and noting is ever sent. Caught by clippy really.
1 parent b7a4dd2 commit 4011d3b

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

iroh-bitswap/src/client/peer_manager.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{fmt::Debug, sync::Arc};
22

33
use ahash::{AHashMap, AHashSet};
4-
use anyhow::Result;
4+
use anyhow::{Context, Result};
55
use cid::Cid;
66
use derivative::Derivative;
77
use futures::{future::BoxFuture, FutureExt};
@@ -658,10 +658,15 @@ impl PeerManagerActor {
658658
) {
659659
if let Some(session) = self.sessions.get(&session) {
660660
if session.peers.contains(&peer) {
661-
self.network.protect_peer(peer).await;
661+
self.network
662+
.protect_peer(peer)
663+
.await
664+
.context("Failed to protect connection")
665+
.map_err(|err| error!("{err:#}"))
666+
.ok();
662667
}
663668
}
664-
let _ = response.send(());
669+
response.send(()).ok();
665670
}
666671

667672
async fn remove_peer_from_session(

iroh-bitswap/src/network.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ use std::{
66
time::Duration,
77
};
88

9-
use anyhow::{anyhow, bail, Result};
9+
use anyhow::{anyhow, bail, Context as _, Result};
1010
use cid::Cid;
1111
use futures::Stream;
1212
use iroh_metrics::{bitswap::BitswapMetrics, inc};
1313
use iroh_metrics::{core::MRecorder, record};
1414
use libp2p::{core::connection::ConnectionId, PeerId};
1515
use tokio::sync::{mpsc, oneshot};
16-
use tracing::{debug, info, trace};
16+
use tracing::{debug, error, info, trace};
1717

1818
use crate::{message::BitswapMessage, protocol::ProtocolId, BitswapEvent};
1919

@@ -297,18 +297,24 @@ impl Network {
297297
trace!("untag {}: {}", peer, tag);
298298
}
299299

300-
pub async fn protect_peer(&self, peer: PeerId) {
300+
pub async fn protect_peer(&self, peer: PeerId) -> Result<()> {
301301
trace!("protect {}", peer);
302-
let _ = self.network_out_sender.send(OutEvent::ProtectPeer { peer });
302+
self.network_out_sender
303+
.send(OutEvent::ProtectPeer { peer })
304+
.await?;
305+
Ok(())
303306
}
304307

305308
pub async fn unprotect_peer(&self, peer: PeerId) -> bool {
306309
trace!("unprotect {}", peer);
307310

308311
let (s, r) = oneshot::channel();
309-
let _ = self
310-
.network_out_sender
311-
.send(OutEvent::UnprotectPeer { peer, response: s });
312+
self.network_out_sender
313+
.send(OutEvent::UnprotectPeer { peer, response: s })
314+
.await
315+
.context("Failed to unprotect peer")
316+
.map_err(|err| error!("{err:#}"))
317+
.ok();
312318

313319
r.await.unwrap_or_default()
314320
}

0 commit comments

Comments
 (0)