Skip to content

Commit

Permalink
Merge pull request #3 from OneSignal/marked-bad-reason
Browse files Browse the repository at this point in the history
Require a reason for `marked_bad` server fn
  • Loading branch information
alecharmon authored Dec 4, 2023
2 parents 1f2c650 + 2f24f95 commit 53bbc8f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
14 changes: 8 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ where
match write_all_flush(&mut self.write, &response).await {
Ok(_) => (),
Err(err) => {
server.mark_bad();
server.mark_bad(err.clone().to_string().as_str());
return Err(err);
}
};
Expand Down Expand Up @@ -1650,7 +1650,7 @@ where
match write_all_flush(&mut self.write, &response).await {
Ok(_) => (),
Err(err) => {
server.mark_bad();
server.mark_bad(err.clone().to_string().as_str());
return Err(err);
}
};
Expand Down Expand Up @@ -1713,11 +1713,13 @@ where
}
},
Err(_) => {
error!(
"Statement timeout while talking to {:?} with user {}",
address, pool.settings.user.username
server.mark_bad(
format!(
"Statement timeout while talking to {:?} with user {}",
address, pool.settings.user.username
)
.as_str(),
);
server.mark_bad();
pool.ban(address, BanReason::StatementTimeout, Some(client_stats));
error_response_terminal(&mut self.write, "pool statement timeout").await?;
Err(Error::StatementTimeout)
Expand Down
12 changes: 8 additions & 4 deletions src/mirrors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ impl MirroredClient {
match recv_result {
Ok(message) => trace!("Received from mirror: {} {:?}", String::from_utf8_lossy(&message[..]), address.clone()),
Err(err) => {
server.mark_bad();
error!("Failed to receive from mirror {:?} {:?}", err, address.clone());
server.mark_bad(
format!("Failed to receive from mirror {:?} {:?}", err, address.clone()).as_str()
);

}
}
}
Expand All @@ -95,8 +97,10 @@ impl MirroredClient {
match server.send(&BytesMut::from(&bytes[..])).await {
Ok(_) => trace!("Sent to mirror: {} {:?}", String::from_utf8_lossy(&bytes[..]), address.clone()),
Err(err) => {
server.mark_bad();
error!("Failed to send to mirror, Discarding message {:?}, {:?}", err, address.clone())
server.mark_bad(
format!("Failed to send to mirror, Discarding message {:?}, {:?}", err, address.clone()).as_str()
);

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ impl ConnectionPool {
}

// Don't leave a bad connection in the pool.
server.mark_bad();
server.mark_bad("failed health check");

self.ban(&address, BanReason::FailedHealthCheck, Some(client_info));
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1092,8 +1092,8 @@ impl Server {
}

/// Indicate that this server connection cannot be re-used and must be discarded.
pub fn mark_bad(&mut self) {
error!("Server {:?} marked bad", self.address);
pub fn mark_bad(&mut self, reason: &str) {
error!("Server {:?} marked bad, reason: {}", self.address, reason);
self.bad = true;
}

Expand Down

0 comments on commit 53bbc8f

Please sign in to comment.