From c028016428b58d5b2062debdafc60255f7efa7d6 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Mon, 23 Nov 2026 20:42:55 +0000 Subject: [PATCH] Handle TCP resets in the code mode session recovery test (#63454) ## Why The shared-connection release test can fail when the client closes its socket with a TCP reset instead of a clean EOF. ## What changed Use an in-memory stream between the proxy and the gRPC host so only the client socket can report a TCP reset. Accept either a clean close or a client reset as the release signal, propagate other I/O errors, and keep the RPC assertions that rule out an early disconnect. GitOrigin-RevId: 25c2d5093e340da21a19a69916b3f62716e4dd52 --- .../tests/grpc/session_recovery_tests.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/codex-rs/code-mode-host/tests/grpc/session_recovery_tests.rs b/codex-rs/code-mode-host/tests/grpc/session_recovery_tests.rs index 6d675f5c6b..4be814dcea 100644 --- a/codex-rs/code-mode-host/tests/grpc/session_recovery_tests.rs +++ b/codex-rs/code-mode-host/tests/grpc/session_recovery_tests.rs @@ -1,5 +1,6 @@ //! Exercises missing-session recovery while the host's lease streams remain open. +use std::io::ErrorKind; use std::sync::Arc; use std::sync::Mutex; use std::sync::atomic::AtomicBool; @@ -19,7 +20,6 @@ use codex_code_mode_protocol::grpc::code_mode_host_server::CodeModeHostServer; use futures::StreamExt; use pretty_assertions::assert_eq; use tokio::net::TcpListener; -use tokio::net::TcpStream; use tokio_stream::wrappers::TcpListenerStream; use tokio_util::task::AbortOnDropHandle; use tonic::Code; @@ -84,22 +84,25 @@ async fn last_failed_session_releases_the_shared_connection() -> Result<()> { Ok(req) } }); - let host = TcpListener::bind("127.0.0.1:0").await?; - let host_addr = host.local_addr()?; + // Keep the host leg in memory so only the client socket can report a TCP reset. + let (mut host, server) = tokio::io::duplex(/*max_buf_size*/ 8192); let _server = AbortOnDropHandle::new(tokio::spawn( Server::builder() .add_service(service) - .serve_with_incoming(TcpListenerStream::new(host)), + .serve_with_incoming(tokio_stream::once(Ok::<_, std::io::Error>(server))), )); - // Forward exactly one TCP connection. Its EOF is the worker-release signal. + // Accept exactly one connection. The RPC assertions below rule out early disconnects. let listener = TcpListener::bind("127.0.0.1:0").await?; let provider = GrpcCodeModeSessionProvider::new(format!("http://{}", listener.local_addr()?)); let connection = AbortOnDropHandle::new(tokio::spawn(async move { let (mut client, _) = listener.accept().await?; drop(listener); - let mut host = TcpStream::connect(host_addr).await?; - tokio::io::copy_bidirectional(&mut client, &mut host).await + match tokio::io::copy_bidirectional(&mut client, &mut host).await { + Ok(_) => Ok(()), + Err(err) if err.kind() == ErrorKind::ConnectionReset => Ok(()), + Err(err) => Err(err), + } })); let first = provider .create_session()