Files
codex/codex-rs/exec-server/src/rpc_pending_request.rs
jif ed9e5a26a8 Clean up canceled exec-server RPC requests immediately (#49332)
## Why

Canceled RPC calls could leave entries in the pending request map until further traffic or disconnect. Cleanup should happen when the call is dropped, even if no response arrives.

## What changed

Use a `PendingRequestGuard` to remove each registration when its call completes or is canceled. Protect the pending map with a synchronous mutex so cleanup can run in `Drop`, replacing opportunistic pruning and explicit error-path removals.

## Testing

Add a regression test that drops an in-flight call and verifies that the pending request count immediately reaches zero without further traffic.

GitOrigin-RevId: 82c0629f37a2f4bb89b8d10e167e2a09765b26eb
2026-09-29 18:34:48 +00:00

24 lines
662 B
Rust

//! Removes client RPC registrations when their call completes or is canceled.
//! The pending map is locked only for synchronous bookkeeping, including in Drop.
use std::collections::HashMap;
use std::sync::Mutex;
use codex_exec_server_protocol::RequestId;
use super::PendingRequest;
pub(super) struct PendingRequestGuard<'a> {
pub(super) pending: &'a Mutex<HashMap<RequestId, PendingRequest>>,
pub(super) request_id: RequestId,
}
impl Drop for PendingRequestGuard<'_> {
fn drop(&mut self) {
self.pending
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.remove(&self.request_id);
}
}