fix(mysql): keep pool when health probe times out during export
This commit is contained in:
1 file changed
+42
-4
@@ -3352,10 +3352,14 @@ impl AppState {
|
|||||||
checked_mysql_pool = Some(pool.clone());
|
checked_mysql_pool = Some(pool.clone());
|
||||||
drop(connections);
|
drop(connections);
|
||||||
match db::mysql::checkout_mysql_conn(&pool, HEALTH_CHECK_POOL_ACQUIRE_TIMEOUT).await {
|
match db::mysql::checkout_mysql_conn(&pool, HEALTH_CHECK_POOL_ACQUIRE_TIMEOUT).await {
|
||||||
// Pool saturation means active work, not a dead connection. Removing this pool would
|
// The 500 ms probe budget is intentionally shorter than a foreground checkout. A timeout
|
||||||
// start a competing reconnect while foreground queries and metadata are still running.
|
// while waiting, creating, or recycling is inconclusive: slow remote handshakes and active
|
||||||
Err(err) if err.is_pool_saturation() => {
|
// metadata exports can legitimately exceed it. Removing the pool here would start competing
|
||||||
log::debug!("MySQL connection pool '{pool_key}' is busy; skipping health probe: {err}");
|
// reconnects while useful work is still running.
|
||||||
|
Err(err @ db::PoolCheckoutError::Timeout { .. }) => {
|
||||||
|
log::debug!(
|
||||||
|
"MySQL connection pool '{pool_key}' did not finish a health checkout; keeping pool: {err}"
|
||||||
|
);
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -7005,6 +7009,40 @@ mod tests {
|
|||||||
let _ = std::fs::remove_dir_all(dir);
|
let _ = std::fs::remove_dir_all(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn mysql_health_check_keeps_pool_when_connection_creation_exceeds_probe_budget() {
|
||||||
|
let listener = tokio::net::TcpListener::bind(("127.0.0.1", 0)).await.unwrap();
|
||||||
|
let address = listener.local_addr().unwrap();
|
||||||
|
let server = tokio::spawn(async move {
|
||||||
|
let (_socket, _) = listener.accept().await.unwrap();
|
||||||
|
std::future::pending::<()>().await;
|
||||||
|
});
|
||||||
|
let pool_options =
|
||||||
|
mysql_async::PoolOpts::new().with_constraints(mysql_async::PoolConstraints::new(1, 2).unwrap());
|
||||||
|
let options = mysql_async::OptsBuilder::default()
|
||||||
|
.ip_or_hostname(address.ip().to_string())
|
||||||
|
.tcp_port(address.port())
|
||||||
|
.user(Some("fault-injection"))
|
||||||
|
.pass(Some("fault-injection"))
|
||||||
|
.pool_opts(Some(pool_options));
|
||||||
|
let pool = db::mysql::MySqlPool::new(options, 2);
|
||||||
|
let (state, dir) = test_app_state().await;
|
||||||
|
state.connections.write().await.insert("conn".to_string(), PoolKind::Mysql(pool.clone(), MysqlMode::Normal));
|
||||||
|
|
||||||
|
let started = Instant::now();
|
||||||
|
assert!(!state.remove_stale_connection_pool("conn").await);
|
||||||
|
|
||||||
|
assert!(started.elapsed() >= super::HEALTH_CHECK_POOL_ACQUIRE_TIMEOUT);
|
||||||
|
assert!(matches!(
|
||||||
|
state.connections.read().await.get("conn"),
|
||||||
|
Some(PoolKind::Mysql(current, _)) if pool.is_same_pool(current)
|
||||||
|
));
|
||||||
|
state.connections.write().await.remove("conn");
|
||||||
|
server.abort();
|
||||||
|
let _ = tokio::time::timeout(Duration::from_secs(1), pool.disconnect()).await;
|
||||||
|
let _ = std::fs::remove_dir_all(dir);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn jdbc_plugin_env_uses_managed_jre_when_installed() {
|
async fn jdbc_plugin_env_uses_managed_jre_when_installed() {
|
||||||
let dir = std::env::temp_dir().join(format!("dbx-core-jdbc-managed-jre-{}", uuid::Uuid::new_v4()));
|
let dir = std::env::temp_dir().join(format!("dbx-core-jdbc-managed-jre-{}", uuid::Uuid::new_v4()));
|
||||||
|
|||||||
Reference in new issue
Block a user