25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(kingbase): retry plaintext after V7 TLS failure
t8y2ba0f864234c3
diff --git a/agents/drivers/kingbase-go/main.go b/agents/drivers/kingbase-go/main.goindex 2a198293dc..47abc6b042 100644--- a/agents/drivers/kingbase-go/main.go+++ b/agents/drivers/kingbase-go/main.go@@ -511,7 +511,7 @@ func openAndPingDB(cp connectParams, timeout time.Duration, opener kingbaseDBOpeif db != nil {_ = db.Close()}- if index == 0 && len(attempts) == 2 && errors.Is(err, gokb.ErrSSLNotSupported) {+ if index == 0 && len(attempts) == 2 && shouldRetryKingbaseWithoutSSL(err) {continue}return nil, err@@ -519,6 +519,19 @@ func openAndPingDB(cp connectParams, timeout time.Duration, opener kingbaseDBOpereturn nil, errors.New("kingbase connection failed")}+func shouldRetryKingbaseWithoutSSL(err error) bool {+ if errors.Is(err, gokb.ErrSSLNotSupported) {+ return true+ }+ if err == nil {+ return false+ }++ // KingBase V7 can accept the SSLRequest and then reject the TLS handshake,+ // so gokb returns the TLS alert instead of ErrSSLNotSupported.+ return strings.Contains(strings.ToLower(err.Error()), "remote error: tls: handshake failure")+}+func openDBWithSSLMode(cp connectParams, sslMode string) (*sql.DB, error) {dsn := buildDSNWithSSLMode(cp, sslMode)db, err := sql.Open("kingbase", dsn)diff --git a/agents/drivers/kingbase-go/main_test.go b/agents/drivers/kingbase-go/main_test.goindex e378e318b4..282a131ef8 100644--- a/agents/drivers/kingbase-go/main_test.go+++ b/agents/drivers/kingbase-go/main_test.go@@ -851,6 +851,21 @@ func TestOpenAndPingDBPreferFallbackUsesOneTimeoutBudget(t *testing.T) {}}+func TestOpenAndPingDBPreferFallbackHandlesKingbaseV7TLSFailure(t *testing.T) {+ state := &connectionAttemptState{pingErrors: map[string]error{+ "require": errors.New("remote error: tls: handshake failure"),+ }}+ db, err := openAndPingDB(connectParams{}, time.Second, state.open)+ if err != nil {+ t.Fatal(err)+ }+ defer db.Close()+ attempts, _ := state.snapshot()+ if strings.Join(attempts, ",") != "require,disable" {+ t.Fatalf("unexpected KingBase V7 attempts: %v", attempts)+ }+}+func TestOpenAndPingDBDoesNotDowngradeUnrelatedErrors(t *testing.T) {authErr := errors.New("authentication failed")state := &connectionAttemptState{pingErrors: map[string]error{"require": authErr}}@@ -867,6 +882,33 @@ func TestOpenAndPingDBDoesNotDowngradeUnrelatedErrors(t *testing.T) {}}+func TestOpenAndPingDBDoesNotDowngradeNetworkErrors(t *testing.T) {+ tests := []struct {+ name string+ err error+ }{+ {name: "timeout", err: context.DeadlineExceeded},+ {name: "connection refused", err: errors.New("dial tcp 127.0.0.1:54321: connect: connection refused")},+ {name: "generic handshake", err: errors.New("handshake failure")},+ }+ for _, test := range tests {+ t.Run(test.name, func(t *testing.T) {+ state := &connectionAttemptState{pingErrors: map[string]error{"require": test.err}}+ db, err := openAndPingDB(connectParams{}, time.Second, state.open)+ if db != nil {+ db.Close()+ }+ if !errors.Is(err, test.err) {+ t.Fatalf("unexpected error: %v", err)+ }+ attempts, _ := state.snapshot()+ if strings.Join(attempts, ",") != "require" {+ t.Fatalf("network errors must not downgrade: %v", attempts)+ }+ })+ }+}+func TestOpenAndPingDBExplicitModesNeverDowngrade(t *testing.T) {for _, sslMode := range []string{"disable", "require", "verify-ca", "verify-full"} {t.Run(sslMode, func(t *testing.T) {@@ -886,6 +928,26 @@ func TestOpenAndPingDBExplicitModesNeverDowngrade(t *testing.T) {}}+func TestOpenAndPingDBExplicitModesNeverDowngradeKingbaseV7TLSFailure(t *testing.T) {+ tlsErr := errors.New("remote error: tls: handshake failure")+ for _, sslMode := range []string{"disable", "require", "verify-ca", "verify-full"} {+ t.Run(sslMode, func(t *testing.T) {+ state := &connectionAttemptState{pingErrors: map[string]error{sslMode: tlsErr}}+ db, err := openAndPingDB(connectParams{URLParams: "sslmode=" + sslMode}, time.Second, state.open)+ if db != nil {+ db.Close()+ }+ if !errors.Is(err, tlsErr) {+ t.Fatalf("unexpected error: %v", err)+ }+ attempts, _ := state.snapshot()+ if len(attempts) != 1 || attempts[0] != sslMode {+ t.Fatalf("explicit mode must use one attempt: %v", attempts)+ }+ })+ }+}+func TestOpenAndPingDBSSLDefaultsToVerifyFull(t *testing.T) {state := &connectionAttemptState{pingErrors: map[string]error{}}db, err := openAndPingDB(connectParams{SSL: true}, time.Second, state.open)