Skip to content

Remove blocking async from overlay events loop #382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions newsfragments/382.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove blocking async from overlay events loop.
42 changes: 22 additions & 20 deletions trin-history/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl HistoryEvents {
loop {
tokio::select! {
Some(talk_request) = self.event_rx.recv() => {
self.handle_history_talk_request(talk_request).await;
self.handle_history_talk_request(talk_request);
}
Some(event) = self.utp_listener_rx.recv() => {
if let Err(err) = self.network.overlay.process_utp_event(event) {
Expand All @@ -28,25 +28,27 @@ impl HistoryEvents {
}

/// Handle history network TalkRequest event
async fn handle_history_talk_request(&self, talk_request: TalkRequest) {
let reply = match self
.network
.overlay
.process_one_request(&talk_request)
.instrument(tracing::info_span!("history_network"))
.await
{
Ok(response) => {
debug!("Sending reply: {:?}", response);
Message::from(response).into()
}
Err(error) => {
error!("Failed to process portal history event: {error}");
error.to_string().into_bytes()
fn handle_history_talk_request(&self, talk_request: TalkRequest) {
let network = Arc::clone(&self.network);
tokio::spawn(async move {
let reply = match network
.overlay
.process_one_request(&talk_request)
.instrument(tracing::info_span!("history_network"))
.await
{
Ok(response) => {
debug!("Sending reply: {:?}", response);
Message::from(response).into()
}
Err(error) => {
error!("Failed to process portal history event: {error}");
error.to_string().into_bytes()
}
};
if let Err(error) = talk_request.respond(reply) {
warn!("Failed to send reply: {error}");
}
};
if let Err(error) = talk_request.respond(reply) {
warn!("Failed to send reply: {error}");
}
});
}
}
42 changes: 22 additions & 20 deletions trin-state/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl StateEvents {
loop {
tokio::select! {
Some(talk_request) = self.event_rx.recv() => {
self.handle_state_talk_request(talk_request).await;
self.handle_state_talk_request(talk_request);
}
Some(event) = self.utp_listener_rx.recv() => {
if let Err(err) = self.network.overlay.process_utp_event(event) {
Expand All @@ -28,25 +28,27 @@ impl StateEvents {
}

/// Handle state network TalkRequest event
async fn handle_state_talk_request(&self, talk_request: TalkRequest) {
let reply = match self
.network
.overlay
.process_one_request(&talk_request)
.instrument(tracing::info_span!("state_network"))
.await
{
Ok(response) => {
debug!("Sending reply: {:?}", response);
Message::from(response).into()
}
Err(error) => {
error!("Failed to process portal state event: {error}");
error.to_string().into_bytes()
fn handle_state_talk_request(&self, talk_request: TalkRequest) {
let network = Arc::clone(&self.network);
tokio::spawn(async move {
let reply = match network
.overlay
.process_one_request(&talk_request)
.instrument(tracing::info_span!("state_network"))
.await
{
Ok(response) => {
debug!("Sending reply: {:?}", response);
Message::from(response).into()
}
Err(error) => {
error!("Failed to process portal state event: {error}");
error.to_string().into_bytes()
}
};
if let Err(error) = talk_request.respond(reply) {
warn!("Failed to send reply: {error}");
}
};
if let Err(error) = talk_request.respond(reply) {
warn!("Failed to send reply: {error}");
}
});
}
}