mirror of
https://github.com/openai/codex.git
synced 2026-10-20 08:19:50 +00:00
## 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
24 lines
662 B
Rust
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);
|
|
}
|
|
}
|