Skip to content

Commit fdafbc0

Browse files
committed
Require a reason when marking a server bad
When calling mark_bad require a reason so it can be logged rather than the generic message
1 parent bc07dc9 commit fdafbc0

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

src/client.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ where
14371437
.await
14381438
{
14391439
// We might be in some kind of error/in between protocol state
1440-
server.mark_bad();
1440+
server.mark_bad(err.clone().to_string().as_str());
14411441
return Err(err);
14421442
}
14431443

@@ -1504,7 +1504,7 @@ where
15041504
match write_all_flush(&mut self.write, &response).await {
15051505
Ok(_) => (),
15061506
Err(err) => {
1507-
server.mark_bad();
1507+
server.mark_bad(err.clone().to_string().as_str());
15081508
return Err(err);
15091509
}
15101510
};
@@ -1926,7 +1926,7 @@ where
19261926
Ok(_) => (),
19271927
Err(err) => {
19281928
// We might be in some kind of error/in between protocol state, better to just kill this server
1929-
server.mark_bad();
1929+
server.mark_bad(err.clone().to_string().as_str());
19301930
return Err(err);
19311931
}
19321932
};
@@ -1993,11 +1993,13 @@ where
19931993
}
19941994
},
19951995
Err(_) => {
1996-
error!(
1997-
"Statement timeout while talking to {:?} with user {}",
1998-
address, pool.settings.user.username
1996+
server.mark_bad(
1997+
format!(
1998+
"Statement timeout while talking to {:?} with user {}",
1999+
address, pool.settings.user.username
2000+
)
2001+
.as_str(),
19992002
);
2000-
server.mark_bad();
20012003
pool.ban(address, BanReason::StatementTimeout, Some(client_stats));
20022004
error_response_terminal(&mut self.write, "pool statement timeout").await?;
20032005
Err(Error::StatementTimeout)

src/mirrors.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ impl MirroredClient {
8585
match recv_result {
8686
Ok(message) => trace!("Received from mirror: {} {:?}", String::from_utf8_lossy(&message[..]), address.clone()),
8787
Err(err) => {
88-
server.mark_bad();
89-
error!("Failed to receive from mirror {:?} {:?}", err, address.clone());
88+
server.mark_bad(
89+
format!("Failed to send to mirror, Discarding message {:?}, {:?}", err, address.clone()).as_str()
90+
);
9091
}
9192
}
9293
}
@@ -98,8 +99,9 @@ impl MirroredClient {
9899
match server.send(&BytesMut::from(&bytes[..])).await {
99100
Ok(_) => trace!("Sent to mirror: {} {:?}", String::from_utf8_lossy(&bytes[..]), address.clone()),
100101
Err(err) => {
101-
server.mark_bad();
102-
error!("Failed to send to mirror, Discarding message {:?}, {:?}", err, address.clone())
102+
server.mark_bad(
103+
format!("Failed to receive from mirror {:?} {:?}", err, address.clone()).as_str()
104+
);
103105
}
104106
}
105107
}

src/pool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ impl ConnectionPool {
871871
}
872872

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

876876
self.ban(address, BanReason::FailedHealthCheck, Some(client_info));
877877
false

src/server.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1279,8 +1279,8 @@ impl Server {
12791279
}
12801280

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

0 commit comments

Comments
 (0)