fix(agent): discard timed out query pools
This commit is contained in:
1 parent
cef9ce8994
commit
b94f0e1590
2 files changed
+52
-3
No files matched your search
@@ -875,6 +875,17 @@ impl AppState {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn remove_pool_by_key(&self, pool_key: &str) -> bool {
|
||||
self.stop_keepalive_task(pool_key).await;
|
||||
let removed = self.connections.write().await.remove(pool_key);
|
||||
if let Some(pool) = removed {
|
||||
close_pool_kind(pool).await;
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn close_database_pool(&self, connection_id: &str, database: Option<&str>) -> Result<bool, String> {
|
||||
let db_type = {
|
||||
let configs = self.configs.read().await;
|
||||
|
||||
@@ -641,7 +641,7 @@ pub fn agent_close_query_session_params(session_id: &str) -> serde_json::Value {
|
||||
|
||||
pub fn is_connection_error(err: &str) -> bool {
|
||||
let lower = err.to_lowercase();
|
||||
if is_dbx_query_timeout_error(&lower) {
|
||||
if is_dbx_query_timeout_error(&lower) || is_agent_rpc_timeout_error(&lower) {
|
||||
return false;
|
||||
}
|
||||
lower.contains("connection")
|
||||
@@ -656,6 +656,10 @@ pub fn is_connection_error(err: &str) -> bool {
|
||||
|| lower.contains("not connected")
|
||||
|| lower.contains("end-of-file")
|
||||
|| lower.contains("idle")
|
||||
|| lower.contains("agent stdin not available")
|
||||
|| lower.contains("agent stdout not available")
|
||||
|| lower.contains("failed to write to agent stdin")
|
||||
|| lower.contains("failed to flush agent stdin")
|
||||
|| lower.contains("communicating with the server")
|
||||
|| is_os_connection_error(&lower)
|
||||
}
|
||||
@@ -664,6 +668,21 @@ fn is_dbx_query_timeout_error(lower: &str) -> bool {
|
||||
lower.starts_with("query timed out after ")
|
||||
}
|
||||
|
||||
fn is_agent_rpc_timeout_error(lower: &str) -> bool {
|
||||
lower.starts_with("agent rpc call timed out ")
|
||||
}
|
||||
|
||||
fn should_discard_agent_pool_after_error(err: &str) -> bool {
|
||||
let lower = err.to_lowercase();
|
||||
is_dbx_query_timeout_error(&lower)
|
||||
|| is_agent_rpc_timeout_error(&lower)
|
||||
|| lower.contains("agent stdin not available")
|
||||
|| lower.contains("agent stdout not available")
|
||||
|| lower.contains("failed to write to agent stdin")
|
||||
|| lower.contains("failed to flush agent stdin")
|
||||
|| lower.contains("agent rpc task failed")
|
||||
}
|
||||
|
||||
fn is_os_connection_error(lower: &str) -> bool {
|
||||
let os_error_codes = ["10053", "10054", "10057", "10058", "10060", "10061"];
|
||||
if let Some(pos) = lower.find("os error ") {
|
||||
@@ -922,7 +941,7 @@ pub async fn do_execute(
|
||||
let max_rows = options.max_rows;
|
||||
let rpc_timeout = query_timeout;
|
||||
drop(connections);
|
||||
wait_for_query_opt(cancel_token, query_timeout, async move {
|
||||
let result = wait_for_query_opt(cancel_token, query_timeout, async move {
|
||||
let mut client = client.lock().await;
|
||||
if let Some(session_id) = options.result_session_id.as_deref() {
|
||||
let params = agent_fetch_query_page_params(session_id, options.page_size.unwrap_or(MAX_ROWS));
|
||||
@@ -936,7 +955,11 @@ pub async fn do_execute(
|
||||
}
|
||||
})
|
||||
.await
|
||||
.map(|result| normalize_query_result_for_js(truncate_result_with_max_rows(result, max_rows)))
|
||||
.map(|result| normalize_query_result_for_js(truncate_result_with_max_rows(result, max_rows)));
|
||||
if matches!(result.as_ref(), Err(err) if should_discard_agent_pool_after_error(err)) {
|
||||
state.remove_pool_by_key(pool_key).await;
|
||||
}
|
||||
result
|
||||
}
|
||||
#[cfg(feature = "duckdb-bundled")]
|
||||
PoolKind::ExternalTabular(ext_pool) => {
|
||||
@@ -2366,6 +2389,21 @@ mod tests {
|
||||
assert_eq!(params["sessionId"], "session-1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn agent_timeout_discards_pool_but_does_not_retry_same_query() {
|
||||
assert!(should_discard_agent_pool_after_error("Query timed out after 30 seconds"));
|
||||
assert!(should_discard_agent_pool_after_error("Agent RPC call timed out (30s)"));
|
||||
assert!(!is_connection_error("Agent RPC call timed out (30s)"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unavailable_agent_pipes_are_reconnectable_errors() {
|
||||
assert!(should_discard_agent_pool_after_error("Agent stdin not available"));
|
||||
assert!(should_discard_agent_pool_after_error("Agent stdout not available"));
|
||||
assert!(is_connection_error("Agent stdin not available"));
|
||||
assert!(is_connection_error("Agent stdout not available"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn query_results_convert_unsafe_json_integers_to_strings_for_js() {
|
||||
let result = db::QueryResult {
|
||||
|
||||
Reference in new issue
Block a user