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 deadloop if proxy_handle_upstream exit early than proxy_handle_downstream #480

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
8 changes: 5 additions & 3 deletions pingora-core/src/protocols/http/v2/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,15 @@ impl HttpSession {

/// Whether there is no more body to read
pub fn is_body_done(&self) -> bool {
self.request_body_reader.is_end_stream()
// Check no body in request
// Also check we hit end of stream if request carry body.
self.is_body_empty() || (self.body_read > 0 && self.request_body_reader.is_end_stream())
taikulawo marked this conversation as resolved.
Show resolved Hide resolved
}

/// Whether there is any body to read.
/// Whether there is any body to read. false means there no body in request.
taikulawo marked this conversation as resolved.
Show resolved Hide resolved
pub fn is_body_empty(&self) -> bool {
self.body_read == 0
&& (self.is_body_done()
&& (self.request_body_reader.is_end_stream()
|| self
.request_header
.headers
Expand Down
4 changes: 3 additions & 1 deletion pingora-proxy/src/proxy_h1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ impl<SV> HttpProxy<SV> {
},

_ = tx.reserve(), if downstream_state.is_reading() && send_permit.is_err() => {
debug!("waiting for permit {send_permit:?}");
// If tx is closed, downstream already finish its job.
downstream_state.maybe_finished(tx.is_closed());
debug!("waiting for permit {send_permit:?}, downstream closed {}", tx.is_closed());
/* No permit, wait on more capacity to avoid starving.
* Otherwise this select only blocks on rx, which might send no data
* before the entire body is uploaded.
Expand Down
Loading