v1 closing

This commit is contained in:
jif-oai
2026-03-25 11:17:36 +00:00
parent a5b99aa0b8
commit a2cda61546
3 changed files with 93 additions and 5 deletions

View File

@@ -360,12 +360,19 @@ impl ExecServerClient {
&& let Err(err) =
handle_server_notification(&inner, notification).await
{
let _ = err;
fail_all_sessions(
&inner,
format!("exec-server notification handling failed: {err}"),
)
.await;
return;
}
}
RpcClientEvent::Disconnected { reason } => {
let _ = reason;
if let Some(inner) = weak.upgrade() {
fail_all_sessions(&inner, disconnected_message(reason.as_deref()))
.await;
}
return;
}
}
@@ -407,6 +414,32 @@ impl From<RpcCallError> for ExecServerError {
}
}
fn disconnected_message(reason: Option<&str>) -> String {
match reason {
Some(reason) => format!("exec-server transport disconnected: {reason}"),
None => "exec-server transport disconnected".to_string(),
}
}
async fn fail_all_sessions(inner: &Arc<Inner>, message: String) {
let sessions = {
let _sessions_write_guard = inner.sessions_write_lock.lock().await;
let sessions = inner.sessions.load();
let drained_sessions = sessions.as_ref().clone();
inner.sessions.store(Arc::new(HashMap::new()));
drained_sessions
};
for (_, events_tx) in sessions {
// Do not block disconnect handling behind a full bounded queue. Best
// effort deliver a terminal failure event, then drop the sender so
// receivers still observe EOF if the queue was already saturated.
let _ = events_tx.try_send(ExecSessionEvent::Failed {
message: message.clone(),
});
}
}
async fn handle_server_notification(
inner: &Arc<Inner>,
notification: JSONRPCNotification,