fix(agent): enforce Oracle and Xugu query timeouts

This commit is contained in:
Abeautifulsnow authored and GitHub committed 2026-07-16 18:00:08 +08:00
1 parent dd3a2e30a4
commit d9ef8b0cac
6 files changed
+601 -31

No files matched your search

+41
View File
@@ -518,6 +518,8 @@ pub struct AgentTableReadStartParams {
pub max_rows: usize,
#[serde(skip_serializing_if = "Option::is_none")]
pub fetch_size: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none")]
pub timeout_secs: Option<u64>,
}
#[derive(Debug, Clone, Serialize)]
@@ -2359,6 +2361,7 @@ for line in sys.stdin:
page_size: 500,
max_rows: 1000,
fetch_size: Some(500),
timeout_secs: None,
})
.unwrap();
assert_eq!(
@@ -2381,6 +2384,44 @@ for line in sys.stdin:
assert_eq!(close, serde_json::json!({ "sessionId": "table-1" }));
}
#[test]
fn serializes_table_read_timeout_secs() {
let with_timeout = serde_json::to_value(AgentTableReadStartParams {
sql: "SELECT 1".to_string(),
database: None,
schema: None,
page_size: 100,
max_rows: 1000,
fetch_size: None,
timeout_secs: Some(30),
})
.unwrap();
assert_eq!(
with_timeout,
serde_json::json!({
"sql": "SELECT 1",
"pageSize": 100,
"maxRows": 1000,
"timeoutSecs": 30,
})
);
let without_timeout = serde_json::to_value(AgentTableReadStartParams {
sql: "SELECT 1".to_string(),
database: None,
schema: None,
page_size: 100,
max_rows: 1000,
fetch_size: None,
timeout_secs: None,
})
.unwrap();
assert!(
!without_timeout.as_object().unwrap().contains_key("timeoutSecs"),
"timeoutSecs key should be absent when None"
);
}
#[test]
fn agent_query_result_default_column_types_is_empty_vec() {
// Old agent JARs predate the column_types field. Rust tolerates the
+11 -1
View File
@@ -7,7 +7,7 @@ use std::time::Duration;
use tokio_util::sync::CancellationToken;
use crate::connection::MysqlMode;
use crate::connection::{task_client_session_id, AppState, PoolKind};
use crate::connection::{config_for_pool_key, task_client_session_id, AppState, PoolKind};
use crate::csv_export::{escape_csv, format_csv, format_tsv, format_tsv_rows, value_to_csv_text};
pub use crate::database_export::ExportStatus;
use crate::database_export::{
@@ -286,6 +286,15 @@ async fn fetch_table_export_batch(
*table_read_attempted = true;
let sql = table_cursor_sql(request, db_type, col_names, primary_keys);
let max_rows = request.row_limit.unwrap_or(i32::MAX as usize);
let timeout_secs = {
let configs = state.configs.read().await;
let query_timeout = config_for_pool_key(pool_key, &configs).map(|c| c.query_timeout_secs).unwrap_or(0);
if query_timeout == 0 {
None
} else {
Some(query_timeout)
}
};
let params = AgentTableReadStartParams {
sql,
database: Some(request.database.clone()),
@@ -293,6 +302,7 @@ async fn fetch_table_export_batch(
page_size: active_batch_size,
max_rows,
fetch_size: Some(active_batch_size),
timeout_secs,
};
let connections = state.connections.read().await;
let Some(PoolKind::Agent(client)) = connections.get(pool_key) else {