fix: scope query connections by client session
This commit is contained in:
1 parent
ac65508ddb
commit
d326cb0ced
17 files changed
+290
-44
No files matched your search
@@ -114,7 +114,7 @@ fn limited_query_result(result: ChJsonResult, execution_time_ms: u128, max_rows:
|
||||
pub async fn test_connection(client: &ChClient) -> Result<(), String> {
|
||||
let url = format!("{}/?query=SELECT%201", client.base_url);
|
||||
let req = build_request(client, client.http.get(&url));
|
||||
let resp = with_connection_timeout("ClickHouse", async {
|
||||
let resp = with_connection_timeout("ClickHouse", connection_timeout(), async {
|
||||
req.send().await.map_err(|e| format!("ClickHouse connection failed: {e}"))
|
||||
})
|
||||
.await?;
|
||||
|
||||
@@ -60,7 +60,7 @@ impl Clone for EsClient {
|
||||
}
|
||||
|
||||
pub async fn test_connection(client: &EsClient) -> Result<(), String> {
|
||||
let resp = with_connection_timeout("Elasticsearch", async {
|
||||
let resp = with_connection_timeout("Elasticsearch", connection_timeout(), async {
|
||||
client.get("/").send().await.map_err(|e| format!("Elasticsearch connection failed: {e}"))
|
||||
})
|
||||
.await?;
|
||||
|
||||
@@ -13,7 +13,7 @@ pub struct MongoDocumentResult {
|
||||
}
|
||||
|
||||
pub async fn connect(url: &str) -> Result<Client, String> {
|
||||
with_connection_timeout("MongoDB", async {
|
||||
with_connection_timeout("MongoDB", connection_timeout(), async {
|
||||
Client::with_uri_str(url).await.map_err(|e| format!("MongoDB connection failed: {e}"))
|
||||
})
|
||||
.await
|
||||
|
||||
@@ -187,7 +187,7 @@ pub async fn connect(url: &str) -> Result<MySqlPool, String> {
|
||||
fn create_pool(url: &str) -> Result<MySqlPool, String> {
|
||||
let opts = mysql_async::Opts::from_url(&mysql_async_url(url)).map_err(|e| format!("Invalid MySQL URL: {e}"))?;
|
||||
let pool_opts = mysql_async::PoolOpts::new()
|
||||
.with_constraints(mysql_async::PoolConstraints::new(1, 5).unwrap())
|
||||
.with_constraints(mysql_async::PoolConstraints::new(1, 1).unwrap())
|
||||
.with_inactive_connection_ttl(Duration::from_secs(300));
|
||||
let builder =
|
||||
mysql_async::OptsBuilder::from_opts(opts).stmt_cache_size(0).prefer_socket(false).pool_opts(Some(pool_opts));
|
||||
@@ -797,35 +797,35 @@ mod tests {
|
||||
#[test]
|
||||
fn parse_connect_timeout_extracts_underscore_form() {
|
||||
let url = "mysql://host:3306/db?connect_timeout=30";
|
||||
assert_eq!(super::parse_connect_timeout(url), Duration::from_secs(30));
|
||||
assert_eq!(crate::db::parse_connect_timeout(url), Duration::from_secs(30));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_connect_timeout_extracts_camelcase_form() {
|
||||
let url = "mysql://host:3306/db?connectTimeout=60";
|
||||
assert_eq!(super::parse_connect_timeout(url), Duration::from_secs(60));
|
||||
assert_eq!(crate::db::parse_connect_timeout(url), Duration::from_secs(60));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_connect_timeout_ignores_out_of_range() {
|
||||
let default = super::connection_timeout();
|
||||
let default = crate::db::connection_timeout();
|
||||
let url = "mysql://host:3306/db?connect_timeout=999";
|
||||
assert_eq!(super::parse_connect_timeout(url), default);
|
||||
assert_eq!(crate::db::parse_connect_timeout(url), default);
|
||||
let url2 = "mysql://host:3306/db?connect_timeout=0";
|
||||
assert_eq!(super::parse_connect_timeout(url2), default);
|
||||
assert_eq!(crate::db::parse_connect_timeout(url2), default);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_connect_timeout_returns_default_when_missing() {
|
||||
let default = super::connection_timeout();
|
||||
let default = crate::db::connection_timeout();
|
||||
let url = "mysql://host:3306/db?ssl-mode=preferred&charset=utf8mb4";
|
||||
assert_eq!(super::parse_connect_timeout(url), default);
|
||||
assert_eq!(crate::db::parse_connect_timeout(url), default);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_connect_timeout_returns_default_when_no_query() {
|
||||
let default = super::connection_timeout();
|
||||
let default = crate::db::connection_timeout();
|
||||
let url = "mysql://host:3306/db";
|
||||
assert_eq!(super::parse_connect_timeout(url), default);
|
||||
assert_eq!(crate::db::parse_connect_timeout(url), default);
|
||||
}
|
||||
}
|
||||
@@ -125,7 +125,7 @@ pub async fn connect(url: &str) -> Result<Pool, String> {
|
||||
|
||||
let tz = iana_time_zone::get_timezone().unwrap_or_else(|_| "UTC".to_string());
|
||||
|
||||
super::with_connection_timeout("PostgreSQL", async {
|
||||
super::with_connection_timeout("PostgreSQL", super::connection_timeout(), async {
|
||||
let pg_config =
|
||||
tokio_postgres::Config::from_str(url).map_err(|e| format!("Invalid PostgreSQL connection URL: {e}"))?;
|
||||
|
||||
@@ -139,7 +139,7 @@ pub async fn connect(url: &str) -> Result<Pool, String> {
|
||||
mgr_config,
|
||||
);
|
||||
let pool = Pool::builder(mgr)
|
||||
.max_size(10)
|
||||
.max_size(1)
|
||||
.runtime(Runtime::Tokio1)
|
||||
.wait_timeout(Some(super::connection_timeout()))
|
||||
.build()
|
||||
|
||||
Reference in new issue
Block a user