HTTP/1.1 read chunked body not correctly
Opened this issue · 2 comments
Describe the bug
When the request type is chunk, the last chunk should be \x30\x0b\x0a\x0b\x0a, which is equivalent to 0\r\n\r\n. However, it seems that the http1 server session only reads 0\r\n, which causes read_body_or_idle to read the remaining data and report an error "Sent data after end of body...". I tried to construct the last chunk as 0\r\n instead of 0\r\n\r\n, and the request ended normally (this should actually be non-standard?)
Pingora info
Please include the following information about your environment:
Pingora version: 0.4.0
Rust version: 1.85.0
Operating system version: centos8
Steps to reproduce
smallest official example:
main.rs:
use std::sync::Arc;
use async_trait::async_trait;
use pingora::{lb::LoadBalancer, prelude::{HttpPeer, RoundRobin}, proxy::{http_proxy_service, ProxyHttp, Session}, server::Server};
const DEFAULT_BACKEND: &str = "x.x.x.x:80"; // some http server that can handle chunked encoding
fn main() {
let mut my_server = Server::new(None).unwrap();
my_server.bootstrap();
let upstreams =
LoadBalancer::try_from_iter([DEFAULT_BACKEND]).unwrap();
let mut lb = http_proxy_service(&my_server.configuration, LB(Arc::new(upstreams)));
lb.add_tcp("0.0.0.0:6188");
my_server.add_service(lb);
my_server.run_forever();
}
pub struct LB(Arc<LoadBalancer<RoundRobin>>);
#[async_trait]
impl ProxyHttp for LB {
/// For this small example, we don't need context storage
type CTX = ();
fn new_ctx(&self) -> () {
()
}
async fn upstream_peer(&self, _session: &mut Session, _ctx: &mut ()) -> pingora::Result<Box<HttpPeer>> {
let upstream = self.0
.select(b"", 256) // hash doesn't matter for round robin
.unwrap();
println!("upstream peer is: {upstream:?}");
// Set SNI to one.one.one.one
let peer = Box::new(HttpPeer::new(upstream, false, "one.one.one.one".to_string()));
Ok(peer)
}
}
Keep sending chunk requests, you will occasionally get a 400 error, and debugging will give you the results I showed above.
And if you set the log level to trace, you can see the relevant logs when errors occur:
Normally, it reads:
Expected results
last chunk read normally.
Observed results
What actually happened?
error message with "Sent data after end of body"
What other information would you like to provide? e.g. screenshots, how you're working around the
issue, or other clues you think could be helpful to identify the root cause.
I debugged it and it may be related to this issue:
@drcaramelsyrup Is there a plan to resolve this bug?

