Skip to content

Commit

Permalink
to avoid positive error feedback loop (#123)
Browse files Browse the repository at this point in the history
Make sure we return handling errors ONLY for
requests. if this is a response message or an error
by itself, we don't respond to that.
  • Loading branch information
muhamadazmy authored Feb 27, 2023
1 parent 2a724fe commit 5bd4368
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/peer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ where
};

// we track these here in case we need to send an error
let is_request = envelope.has_request();
let uid = envelope.uid.clone();
let source = envelope.source.clone();
match self.handle_envelope(envelope).await {
Expand All @@ -472,18 +473,24 @@ where
// but this error happened after the envelope has been
// decoded, so we have enough information to actually send
// back an error response.
let mut e = MessageError::new();
e.code = kind.code();
e.message = kind.to_string();

let mut response = Envelope::new();
response.set_error(e);
response.uid = uid;
response.destination = source;
response.expiration = 300;

if let Err(err) = self.sender.send(response).await {
log::error!("failed to push error response back to caller: {:#}", err);
log::debug!("error while handling incoming message ({}): {}", uid, kind);
if is_request {
// only send handling error back in case of request
// if this a response message or itself is an error
// message do nothing.
let mut e = MessageError::new();
e.code = kind.code();
e.message = kind.to_string();

let mut response = Envelope::new();
response.set_error(e);
response.uid = uid;
response.destination = source;
response.expiration = 300;

if let Err(err) = self.sender.send(response).await {
log::error!("failed to push error response back to caller: {:#}", err);
}
}
}
Err(err) => log::error!("error while handling received message: {:#}", err),
Expand Down

0 comments on commit 5bd4368

Please sign in to comment.