Skip to content

Commit bb111aa

Browse files
taikulawobrk0v
authored andcommitted
fix deadloop if proxy_handle_upstream exit early than proxy_handle_downstream
Includes-commit: 87a0483 Includes-commit: 1978a26 Includes-commit: f9730f6 Includes-commit: 141996d Includes-commit: b841568 Includes-commit: 67283ad Includes-commit: d644ecc Replicated-from: #480 Co-authored-by: Viacheslav Biriukov <[email protected]>
1 parent 343fc98 commit bb111aa

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

.bleep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ce25a5ec3f6937d70f6a60b79adb6dd299144a84
1+
32635fba2c86e17defba5601199d11373dce0bea

pingora-core/src/protocols/http/v2/server.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,15 @@ impl HttpSession {
387387

388388
/// Whether there is no more body to read
389389
pub fn is_body_done(&self) -> bool {
390-
self.request_body_reader.is_end_stream()
390+
// Check no body in request
391+
// Also check we hit end of stream
392+
self.is_body_empty() || self.request_body_reader.is_end_stream()
391393
}
392394

393-
/// Whether there is any body to read.
395+
/// Whether there is any body to read. true means there no body in request.
394396
pub fn is_body_empty(&self) -> bool {
395397
self.body_read == 0
396-
&& (self.is_body_done()
398+
&& (self.request_body_reader.is_end_stream()
397399
|| self
398400
.request_header
399401
.headers

pingora-proxy/src/proxy_h1.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ impl<SV> HttpProxy<SV> {
311311
},
312312

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

0 commit comments

Comments
 (0)