Skip to content
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

Fix empty request streaming hanging forever #2592

Merged
merged 4 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 changelog.d/2590.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix empty request streaming hanging forever
18 changes: 15 additions & 3 deletions mirrord/agent/src/steal/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use tokio::{
sync::mpsc::{Receiver, Sender},
};
use tokio_util::sync::CancellationToken;
use tracing::warn;

use crate::{
error::{AgentError, Result},
Expand Down Expand Up @@ -154,6 +155,7 @@ impl Client {
let tx = self.tx.clone();

tokio::spawn(async move {
tracing::trace!(?connection_id, ?chunked, ?framed, "starting request");
// Chunked data is preferred over framed data
if chunked {
// Send headers
Expand All @@ -171,7 +173,9 @@ impl Client {
) = request.request.into_parts();
match body.next_frames(true).await {
Err(..) => return,
Ok(Frames { frames, is_last }) => {
// We don't check is_last here since loop will finish when body.next_frames()
// returns None
Ok(Frames { frames, .. }) => {
let frames = frames
.into_iter()
.map(InternalHttpBodyFrame::try_from)
Expand All @@ -190,7 +194,9 @@ impl Client {
request_id,
port: request.port,
}));
if tx.send(message).await.is_err() || is_last {

if let Err(e) = tx.send(message).await {
warn!(?e, ?connection_id, ?request_id, ?request.port, "failed to send chunked request start");
return;
}
}
Expand All @@ -212,7 +218,13 @@ impl Client {
request_id,
},
));
if tx.send(message).await.is_err() || is_last {

if let Err(e) = tx.send(message).await {
warn!(?e, ?connection_id, ?request_id, ?request.port, "failed to send chunked request body");
return;
}

if is_last {
return;
}
}
Expand Down