fix(connection): 修复数据库连接超时后无法可靠恢复的问题

* feat(core): implement PIP-0001 database connection timeout recovery

- Add DbOperationBudget struct for unified execution budget model
- Add deadpool create/recycle timeout for PostgreSQL pools
- Add checkout_postgres_client helper replacing 14 bare pool.get() calls
  with timeout + cancel token support
- Fix PostgreSQL TLS cancel: rebuild TLS connector from stored context,
  fallback to NoTls on failure
- Add timeout to MySQL kill_query and kill_query_with_opts (5s)
- Extend is_connection_error to match deadpool pool timeout messages
- Unify keepalive default to 30s (was 60s Rust / 0s frontend mismatch)
- Inject PostgreSQL TCP keepalive params (idle=30s, interval=10s, retries=3)
- Inject MySQL tcp_keepalive=30s in OptsBuilder
- Make MySQL inactive_connection_ttl configurable from idle_timeout_secs
- Add stage-based structured logging for pool.checkout/health.check/cancel
- Store PostgresCancelContext in AppState for TLS cancel reconstruction
- Clean up cancel contexts on pool removal/drain
- Add unit tests for DbOperationBudget and pool timeout error detection

* fix(core): align timeout recovery with PIP-0001

* fix(core): handle timeout recovery review issues

* fix(core): complete connection timeout recovery

* fix(core): fall back postgres cancel connector build

* refactor: revert comment translations to English in connection.rs and query.rs

- Revert DbOperationBudget doc comments to English (query.rs)
- Revert PostgresCancelContext and TLS cancel comments to English (connection.rs)
- Keep Chinese error-matching strings in is_connection_error unchanged

---------

Co-authored-by: onceMisery <onceMisery@users.noreply.github.com>
This commit is contained in:
miracleandonceMisery authored and GitHub committed 2026-06-26 21:41:56 +08:00
1 parent 796b0ce5b7
commit d128604743
11 files changed
+1134 -169

No files matched your search

@@ -135,7 +135,7 @@ const defaultForm = (): ConnectionForm => ({
connect_timeout_secs: 10,
query_timeout_secs: 30,
idle_timeout_secs: 60,
keepalive_interval_secs: 0,
keepalive_interval_secs: 30,
ssl: false,
ca_cert_path: "",
client_cert_path: "",
@@ -908,7 +908,7 @@ watch(
connect_timeout_secs: config.connect_timeout_secs || 10,
query_timeout_secs: config.query_timeout_secs ?? 30,
idle_timeout_secs: config.idle_timeout_secs ?? 60,
keepalive_interval_secs: config.keepalive_interval_secs ?? 0,
keepalive_interval_secs: config.keepalive_interval_secs ?? 30,
ssl: config.ssl || false,
ca_cert_path: config.ca_cert_path || "",
client_cert_path: config.client_cert_path || "",
@@ -1523,7 +1523,7 @@ function connectionConfigForSubmit(id: string): ConnectionConfig {
const idleTimeout = Number(config.idle_timeout_secs);
config.idle_timeout_secs = Number.isFinite(idleTimeout) && idleTimeout >= 0 ? idleTimeout : 60;
const keepaliveInterval = Number(config.keepalive_interval_secs);
config.keepalive_interval_secs = Number.isFinite(keepaliveInterval) && keepaliveInterval >= 0 ? keepaliveInterval : 0;
config.keepalive_interval_secs = Number.isFinite(keepaliveInterval) && keepaliveInterval >= 0 ? keepaliveInterval : 30;
if (config.db_type === "manticoresearch") {
config.url_params = "";
}