Skip to content

Commit ffd6f4f

Browse files
authored
use try_send for external request-response messages (#4386)
* use try_send for external request-response messages * clippy
1 parent 9d5bb51 commit ffd6f4f

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

crates/espresso/node/src/external_event_handler.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::sync::Arc;
44

5-
use anyhow::{Context, Result};
5+
use anyhow::{Context, Result, bail};
66
use espresso_types::{PubKey, SeqTypes};
77
use hotshot::types::Message;
88
use hotshot_types::{
@@ -11,7 +11,7 @@ use hotshot_types::{
1111
};
1212
use request_response::network::Bytes;
1313
use serde::{Deserialize, Serialize};
14-
use tokio::sync::mpsc::{Receiver, Sender};
14+
use tokio::sync::mpsc::{Receiver, Sender, error::TrySendError};
1515
use vbs::{BinarySerializer, bincode_serializer::BincodeSerializer, version::StaticVersion};
1616

1717
use crate::context::TaskList;
@@ -69,13 +69,16 @@ impl ExternalEventHandler {
6969
// Match the type
7070
match external_message {
7171
ExternalMessage::RequestResponse(request_response) => {
72-
// Send the inner message to the request-response protocol
73-
self.request_response_sender
74-
.send(request_response.into())
75-
.await?;
72+
match self
73+
.request_response_sender
74+
.try_send(request_response.into())
75+
{
76+
Ok(()) => Ok(()),
77+
Err(TrySendError::Full(..)) => bail!("request-response channel full"),
78+
Err(TrySendError::Closed(..)) => bail!("request-response channel closed"),
79+
}
7680
},
7781
}
78-
Ok(())
7982
}
8083

8184
/// The main loop for sending outbound messages.

0 commit comments

Comments
 (0)