From bb111aaa92b3753e650957df3a68f56b0cffc65d Mon Sep 17 00:00:00 2001 From: taikulawo Date: Sat, 23 Nov 2024 15:26:57 +0800 Subject: fix deadloop if proxy_handle_upstream exit early than proxy_handle_downstream Includes-commit: 87a0483e19cd79907f6a9851eecaac5d0a1bf4b1 Includes-commit: 1978a261816afbe5bf1cf56977dbc67e2d6cba1a Includes-commit: f9730f6c71dc8a3ecf57e8e1a512462bbb6b7ea4 Includes-commit: 141996d93c6b088edc81a70bf062ed41154c8c74 Includes-commit: b8415685cb192e0d11f4cfb751e01eb26b8a5e5f Includes-commit: 67283ad69f6ea04e219ac827bb9cf7cc4808da06 Includes-commit: d644ecc4186ccbf65442defff4fa34c2307d6a0a Replicated-from: https://github.com/cloudflare/pingora/pull/480 Co-authored-by: Viacheslav Biriukov --- .bleep | 2 +- pingora-core/src/protocols/http/v2/server.rs | 8 +++++--- pingora-proxy/src/proxy_h1.rs | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.bleep b/.bleep index c867e31..f999f12 100644 --- a/.bleep +++ b/.bleep @@ -1 +1 @@ -ce25a5ec3f6937d70f6a60b79adb6dd299144a84 \ No newline at end of file +32635fba2c86e17defba5601199d11373dce0bea \ No newline at end of file diff --git a/pingora-core/src/protocols/http/v2/server.rs b/pingora-core/src/protocols/http/v2/server.rs index 6d6b393..718ddde 100644 --- a/pingora-core/src/protocols/http/v2/server.rs +++ b/pingora-core/src/protocols/http/v2/server.rs @@ -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 + self.is_body_empty() || self.request_body_reader.is_end_stream() } - /// Whether there is any body to read. + /// Whether there is any body to read. true means there no body in request. 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 diff --git a/pingora-proxy/src/proxy_h1.rs b/pingora-proxy/src/proxy_h1.rs index 544a74e..e13d4c1 100644 --- a/pingora-proxy/src/proxy_h1.rs +++ b/pingora-proxy/src/proxy_h1.rs @@ -311,7 +311,9 @@ impl HttpProxy { }, _ = 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. -- cgit v1.2.3