Skip to content

Commit

Permalink
fix(network): notify the request sender on response decoding error (#102
Browse files Browse the repository at this point in the history
)
  • Loading branch information
laplab authored Aug 1, 2023
1 parent 0fb49d5 commit 5cdba27
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 25 additions & 1 deletion elfo-network/src/worker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 5cdba27

Please sign in to comment.