mirror of
https://github.com/openai/codex.git
synced 2026-11-18 22:20:48 +00:00
Flush HTTP/2 tunnel data to the local TCP writer (#62186)
## Why An interactive tunnel can stall when a buffered local writer holds data that the client needs before it can reply. ## What changed Flush the local TCP writer after each HTTP/2 data chunk, before releasing receive flow-control capacity. ## Testing Extend the relay test to verify that the client receives the server's initial bytes through a buffered writer before sending its upload. GitOrigin-RevId: 7c6c37a707319ce77f2abb627924337b0c944c32
This commit is contained in:
@@ -216,6 +216,7 @@ pub(super) async fn bridge(
|
||||
while let Some(data) = recv.data().await {
|
||||
let data = data.map_err(|_| stream_error())?;
|
||||
write.write_all(&data).await.context("writing local TCP")?;
|
||||
write.flush().await.context("flushing local TCP")?;
|
||||
recv.flow_control()
|
||||
.release_capacity(data.len())
|
||||
.map_err(|_| stream_error())?;
|
||||
|
||||
@@ -96,8 +96,9 @@ async fn trusted_h2_requires_settings_and_certificate() -> Result<()> {
|
||||
.await?
|
||||
}
|
||||
|
||||
/// Interactive tunnel responses must reach buffered writers before either side closes.
|
||||
#[tokio::test]
|
||||
async fn forwards_upload_before_response_and_rejects_before_upload() -> Result<()> {
|
||||
async fn forwards_interactive_data_and_rejects_before_upload() -> Result<()> {
|
||||
timeout(Duration::from_secs(15), async {
|
||||
for status in [200, 403] {
|
||||
let (server, client) = tls_configs()?;
|
||||
@@ -121,6 +122,7 @@ async fn forwards_upload_before_response_and_rejects_before_upload() -> Result<(
|
||||
let mut send = respond.send_response(Response::builder().status(status).body(())?, status != 200)?;
|
||||
let handler = async move {
|
||||
if status != 200 { return Ok::<_, anyhow::Error>(()); }
|
||||
send.send_data(Bytes::from_static(b"kex"), false)?;
|
||||
let mut body = request.into_body();
|
||||
let mut received = Vec::new();
|
||||
while let Some(data) = body.data().await { let data = data?; received.extend_from_slice(&data); body.flow_control().release_capacity(data.len())?; }
|
||||
@@ -142,9 +144,12 @@ async fn forwards_upload_before_response_and_rejects_before_upload() -> Result<(
|
||||
let (input, output) = tokio::io::split(socket);
|
||||
let relay = tokio::spawn(async move {
|
||||
Connection::Http2(sender, Box::new(connection)).admit(request).await?
|
||||
.relay(input, output).await
|
||||
.relay(input, tokio::io::BufWriter::new(output)).await
|
||||
});
|
||||
if status == 200 {
|
||||
let mut prompt = [0; 3];
|
||||
local.read_exact(&mut prompt).await?;
|
||||
assert_eq!(&prompt, b"kex");
|
||||
let mut received = Vec::new();
|
||||
local.write_all(&upload).await?; local.shutdown().await?; local.read_to_end(&mut received).await?;
|
||||
assert_eq!(received.len(), download.len());
|
||||
|
||||
Reference in New Issue
Block a user