fix: resolve MySQL connection state desync after disconnect/reconnect
- Use synchronous pool removal in desktop disconnect_db to prevent race condition when user quickly disconnects and reconnects - Rename recordMetadataLoadError to recordConnectionLostError and export it for cross-store reuse - Sync query execution errors back to connection state via recordConnectionLostError in queryStore catch blocks - Add backend check_connection_health method (dbx-core) with Tauri command and web route for proactive pool verification - Add frontend checkConnectionHealth API (tauri.ts/http.ts/api.ts) - Enhance ensureConnected to verify backend pool health before assuming connection is valid, auto-reconnect if stale
This commit is contained in:
1 parent
4346192713
commit
e2f68de455
10 files changed
+92
-24
No files matched your search
@@ -1281,6 +1281,32 @@ impl AppState {
|
||||
self.proxy_tunnels.stop_tunnel(connection_id).await;
|
||||
}
|
||||
|
||||
/// Health-check the base connection pool for a given connection_id.
|
||||
/// Returns `Ok(())` if the pool exists and is healthy, `Err` otherwise.
|
||||
/// If the pool is unhealthy it is removed from the map so subsequent
|
||||
/// `get_or_create_pool` calls will transparently recreate it.
|
||||
pub async fn check_connection_health(&self, connection_id: &str) -> Result<(), String> {
|
||||
let db_type = {
|
||||
let configs = self.configs.read().await;
|
||||
configs.get(connection_id).map(|c| c.db_type)
|
||||
};
|
||||
let pool_key = base_pool_key_for(db_type, connection_id, None, false);
|
||||
|
||||
// Check if pool exists first
|
||||
{
|
||||
let connections = self.connections.read().await;
|
||||
if !connections.contains_key(&pool_key) {
|
||||
return Err("No active connection pool found".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
// `remove_stale_connection_pool` returns true if the pool was stale (and removed)
|
||||
if self.remove_stale_connection_pool(&pool_key).await {
|
||||
return Err("Connection pool is unhealthy".to_string());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn refresh_connections(&self) {
|
||||
// Clone pool handles under a short-lived read lock, then release it
|
||||
// before performing I/O-heavy health checks to avoid blocking writers.
|
||||
|
||||
Reference in new issue
Block a user