v0.2.7-pre.004-fix.001

This commit is contained in:
2026-08-22 18:34:52 +02:00
parent 778ea58ee1
commit 34637848eb
3 changed files with 93 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-onchain-transport-lib/src/ws_session.rs
// version: 1
// version: 2
use futures_util::SinkExt; // rust-rules: trait-import
use futures_util::StreamExt; // rust-rules: trait-import
@@ -262,7 +262,7 @@ async fn handle_session_command<S>(
where
S: tokio::io::AsyncRead + tokio::io::AsyncWrite + std::marker::Unpin,
{
return match command {
match command {
WsSessionCommand::ExecuteJsonRpc { method, params, response_tx } => {
if pending.len() >= endpoint.session().max_pending_requests() {
let error = ksp_core_lib::Error::new(crate::ERROR_CODE_WS_BACKPRESSURE_OVERFLOW, "WebSocket pending JSON-RPC request capacity is exhausted")
@@ -328,7 +328,7 @@ where
}
return true;
},
};
}
}
async fn handle_socket_message<S>(
@@ -479,10 +479,12 @@ fn next_pending_deadline(pending: &std::collections::BTreeMap<u64, PendingWsRequ
fn expire_pending_requests(id: crate::WsSessionId, pending: &mut std::collections::BTreeMap<u64, PendingWsRequest>) {
let now = tokio::time::Instant::now();
let expired_ids = pending
.iter()
.filter_map(|(request_id, request)| if request.deadline <= now { std::option::Option::Some(*request_id) } else { std::option::Option::None })
.collect::<std::vec::Vec<_>>();
let mut expired_ids = std::vec::Vec::new();
for (request_id, request) in pending.iter() {
if request.deadline <= now {
expired_ids.push(*request_id);
}
}
for request_id in expired_ids {
if let std::option::Option::Some(request) = pending.remove(&request_id) {
let error = ws_timeout_error(id, "WebSocket JSON-RPC request timed out while awaiting the remote response").with_context("method", request.method);
@@ -537,8 +539,9 @@ fn publish_snapshot(
}
fn next_session_id() -> ksp_core_lib::Result<crate::WsSessionId> {
let update_result =
NEXT_WS_SESSION_ID.fetch_update(std::sync::atomic::Ordering::Relaxed, std::sync::atomic::Ordering::Relaxed, |current| current.checked_add(1));
let update_result = NEXT_WS_SESSION_ID.fetch_update(std::sync::atomic::Ordering::Relaxed, std::sync::atomic::Ordering::Relaxed, |current| {
return current.checked_add(1);
});
let value = match update_result {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => {