in akd_mysql/src/mysql.rs [193:224]
fn check_for_infra_error<T>(
&self,
result: core::result::Result<T, MySqlError>,
) -> core::result::Result<T, MySqlError> {
match result {
Err(err) => {
let is_connection_infra_error: bool = match &err {
// In mysql_async v0.28.1 TLS errors moved to IoError. Thus we cannot use them here.
// TODO(eoz): Update error handling to take TLS errors into account.
MySqlError::Other(_) | MySqlError::Url(_) /* | mysql_async::IoError::Tls(_) */ => false,
MySqlError::Driver(_) | MySqlError::Io(_) | MySqlError::Server(_) => true,
};
// If error is due to infra error (e.g bad connection) refresh
// connection pool in background. This allows current request to
// finish (with err) while blocking subsequent requests until a
// healthy connection is restored.
if is_connection_infra_error {
let db = self.clone();
tokio::task::spawn(async move {
if let Err(err) = db.refresh_connection_pool().await {
error!("Error refreshing MySql connection pool: {:?}", err);
}
});
}
Err::<T, MySqlError>(err)
}
Ok(t) => Ok(t),
}
}