Skip to content

Commit

Permalink
feat(read_handler): log when max hearbeat missed (#151)
Browse files Browse the repository at this point in the history
* refactor(read_handler): change log from error to warn
* change `MAX_HEARTBEAT_MISS` from `3` to `2`
  • Loading branch information
RoloEdits authored Oct 26, 2024
1 parent de3c858 commit e9c419f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions amqprs/src/net/reader_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ use super::{

/////////////////////////////////////////////////////////////////////////////

const MAX_HEARTBEAT_MISS: u64 = 3;
/// After two missed heartbeats, the peer is considered to be unreachable according to [spec](https://www.rabbitmq.com/docs/heartbeats#heartbeats-interval)
const MAX_HEARTBEAT_MISS: u64 = 2;

pub(crate) struct ReaderHandler {
stream: BufIoReader,
Expand Down Expand Up @@ -261,7 +262,7 @@ impl ReaderHandler {
match res {
Ok((channel_id, frame)) => {
if let Err(err) = self.handle_frame(channel_id, frame).await {
// notifiy network failure
// notify network failure
is_network_failure = true;
#[cfg(feature="traces")]
error!("socket will be closed due to error of handling frame, cause: {}", err);
Expand All @@ -275,7 +276,7 @@ impl ReaderHandler {
}
},
Err(err) => {
// notifiy network failure
// notify network failure
is_network_failure = true;
#[cfg(feature="traces")]
error!("socket will be closed due to failure of reading frame, cause: {}", err);
Expand All @@ -291,9 +292,11 @@ impl ReaderHandler {

// should call self.io_failure_notify.notify_one();?
#[cfg(feature="traces")]
error!("missing heartbeat from server for {}", self.amqp_connection);
warn!("missing heartbeat from server for {}: {heartbeat_miss}/{MAX_HEARTBEAT_MISS}", self.amqp_connection);
heartbeat_miss += 1;
if heartbeat_miss >= MAX_HEARTBEAT_MISS {
#[cfg(feature="traces")]
error!("heartbeat was missed `{heartbeat_miss}` times in a row, closing connection");
// Shutdown connection due to heartbeat timeout
is_network_failure = true;
break;
Expand Down

0 comments on commit e9c419f

Please sign in to comment.