Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(network): notify the request sender on response decoding error #102

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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