fix(connection): recover connection state after VPN failures (#641)

This commit is contained in:
不吃西葫芦 authored and GitHub committed 2026-06-24 01:44:46 +08:00
1 parent 3ebfae05a2
commit 9a0a32e04c
8 files changed
+469 -26

No files matched your search

+15 -5
View File
@@ -512,7 +512,7 @@ async fn drop_mq_adapters_for_connection_ids(_state: &AppState, _connection_ids:
async fn remove_connection_pools_for_connection_ids(state: &AppState, connection_ids: &[String]) {
for connection_id in connection_ids {
state.remove_connection_pools(connection_id).await;
state.remove_connection_pools_detached(connection_id).await;
}
}
@@ -832,10 +832,11 @@ pub async fn connect_db(state: State<'_, Arc<AppState>>, config: ConnectionConfi
let config = config.canonicalized();
let id = config.id.clone();
let db_config = metadata_connection_config(&config);
let attempt = state.begin_connection_attempt(&id).await;
let mut connected_config = config.clone();
let mut connected_db_config = db_config.clone();
state.remove_connection_pools(&id).await;
state.remove_connection_pools_detached(&id).await;
state.reset_connection_transport_for_config(&id, &db_config).await;
let (host, port) = state.connection_host_port(&id, &db_config).await?;
@@ -922,8 +923,16 @@ pub async fn connect_db(state: State<'_, Arc<AppState>>, config: ConnectionConfi
.await
{
Ok(()) => {
state
.insert_connection_pool_for_attempt(
&id,
attempt,
id.clone(),
PoolKind::MongoDb(client),
&db_config,
)
.await?;
state.configs.write().await.insert(id.clone(), config);
state.insert_connection_pool(id.clone(), PoolKind::MongoDb(client), &db_config).await;
return Ok(id);
}
Err(e) => e,
@@ -1085,7 +1094,7 @@ pub async fn connect_db(state: State<'_, Arc<AppState>>, config: ConnectionConfi
db_type => return Err(format!("Unsupported database type: {db_type:?}")),
};
state.insert_connection_pool(id.clone(), pool, &connected_db_config).await;
state.insert_connection_pool_for_attempt(&id, attempt, id.clone(), pool, &connected_db_config).await?;
state.configs.write().await.insert(id.clone(), connected_config);
Ok(id)
@@ -1111,7 +1120,8 @@ pub async fn connection_final_proxy_port(
#[tauri::command]
pub async fn disconnect_db(state: State<'_, Arc<AppState>>, connection_id: String) -> Result<(), String> {
state.remove_connection_pools(&connection_id).await;
state.supersede_connection_attempt(&connection_id).await;
state.remove_connection_pools_detached(&connection_id).await;
drop_nacos_adapters_for_connection_ids(state.inner(), std::slice::from_ref(&connection_id)).await;
drop_mq_adapters_for_connection_ids(state.inner(), std::slice::from_ref(&connection_id)).await;
state.reset_connection_transport(&connection_id).await;