diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ae5b7b8..a296101d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - request: now `RequestError::Ignored` can be returned only if the envelope is received. - macros: allow generic requests in `msg!`: `msg!(match e { (R, token) => .. })`. +- network: notify the request sender on response decoding error ([#102]). + +[#102]: https://github.com/elfo-rs/elfo/pull/102 ## [0.2.0-alpha.4] - 2023-07-06 diff --git a/elfo-network/src/worker/mod.rs b/elfo-network/src/worker/mod.rs index dacb7cc7..3c1f3f06 100644 --- a/elfo-network/src/worker/mod.rs +++ b/elfo-network/src/worker/mod.rs @@ -28,7 +28,10 @@ use self::{ use crate::{ codec::{ decode::EnvelopeDetails, - format::{NetworkEnvelope, NetworkEnvelopePayload, KIND_REQUEST_ALL, KIND_REQUEST_ANY}, + format::{ + NetworkEnvelope, NetworkEnvelopePayload, KIND_REQUEST_ALL, KIND_REQUEST_ANY, + KIND_RESPONSE_FAILED, KIND_RESPONSE_IGNORED, KIND_RESPONSE_OK, + }, }, frame::write::FrameState, protocol::{internode, HandleConnection}, @@ -418,6 +421,27 @@ impl SocketReader { // below. self.tx_flows.add_flow_if_needed(details.sender); sender.respond(token, Err(RequestError::Failed)); + } else if details.kind == KIND_RESPONSE_OK + || details.kind == KIND_RESPONSE_FAILED + || details.kind == KIND_RESPONSE_IGNORED + { + let Some(token) = self + .requests + .lock() + .get_token(details.recipient, details.request_id.expect("bug: request_id is missing"), true) + else { + warn!( + message = "received response to unknown request", + kind = %details.kind, + sender = %details.sender, + recipient = %details.recipient, + request_id = ?details.request_id, + ); + return; + }; + + // Dropped token will notify the request sender that the request failed. + drop(token); } }