{"record":{"id":"efa82db252969379","repo":"t8y2/dbx","slug":"kingbase-connection-failed","errorCode":null,"errorMessage":"kingbase connection failed","messagePattern":"kingbase connection failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"agents/drivers/kingbase-go/main.go","lineNumber":528,"sourceCode":"\t\tattempts = []string{\"require\", \"disable\"}\n\t}\n\tfor index, attempt := range attempts {\n\t\tdb, err := opener(cp, attempt)\n\t\tif err == nil {\n\t\t\terr = db.PingContext(ctx)\n\t\t}\n\t\tif err == nil {\n\t\t\treturn db, nil\n\t\t}\n\t\tif db != nil {\n\t\t\t_ = db.Close()\n\t\t}\n\t\tif index == 0 && len(attempts) == 2 && shouldRetryKingbaseWithoutSSL(err) {\n\t\t\tcontinue\n\t\t}\n\t\treturn nil, err\n\t}\n\treturn nil, errors.New(\"kingbase connection failed\")\n}\n\nfunc shouldRetryKingbaseWithoutSSL(err error) bool {\n\tif errors.Is(err, gokb.ErrSSLNotSupported) {\n\t\treturn true\n\t}\n\tif err == nil {\n\t\treturn false\n\t}\n\n\t// KingBase V7 can accept the SSLRequest and then reject the TLS handshake,\n\t// so gokb returns the TLS alert instead of ErrSSLNotSupported.\n\treturn strings.Contains(strings.ToLower(err.Error()), \"remote error: tls: handshake failure\")\n}\n\nfunc openDBWithSSLMode(cp connectParams, sslMode string) (*sql.DB, error) {\n\tdsn := buildDSNWithSSLMode(cp, sslMode)\n\tdb, err := sql.Open(\"kingbase\", dsn)","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/kingbase-go/main.go#L510-L546","documentation":"This is the fallback error returned by the connection helper when the retry loop over connection attempts exhausts without establishing a session. Each attempt's real error is discarded by the loop, so this generic message masks the underlying cause (auth failure, network refusal, SSL negotiation issue).","triggerScenarios":"All connection attempts (including the retry-without-SSL path when shouldRetryKingbaseWithoutSSL triggers on attempt 0 of 2) returned errors, so control reaches the final return.","commonSituations":"Wrong host/port or Kingbase server down; invalid username/password; SSL required by the driver but unsupported by the server (and vice versa); firewall or DNS problems in containerized environments.","solutions":["Log or inspect the per-attempt error before the loop returns so the real cause is visible instead of the generic fallback","Verify host, port, database, and credentials in the connection parameters","Test SSL behavior: if gokb.ErrSSLNotSupported or SSL mismatch is involved, align the sslmode setting with the server capability","Confirm network reachability (ping/port probe) from the client host to the Kingbase server"],"exampleFix":"// before\n\t\treturn nil, err\n\t}\n\treturn nil, errors.New(\"kingbase connection failed\")\n// after\n\t\treturn nil, fmt.Errorf(\"kingbase connection failed: %w\", err)\n\t}\n\treturn nil, errors.New(\"kingbase connection failed\")","handlingStrategy":"retry","validationCode":"connStr := fmt.Sprintf(\"host=%s port=%s user=%s password=%s dbname=%s sslmode=%s\", host, port, user, pw, db, sslmode); if host == \"\" || db == \"\" { return errors.New(\"host and dbname are required\") }","typeGuard":null,"tryCatchPattern":"db, err := connectKingbase(cp); if err != nil { if errors.Is(err, gokb.ErrSSLNotSupported) { /* retry with sslmode=disable */ }; return fmt.Errorf(\"connect: %w\", err) }","preventionTips":["Wrap the final error with %w so the underlying per-attempt cause is preserved","Validate DSN fields (host, port, credentials, sslmode) before attempting connection","Pre-flight network connectivity checks and correct SSL settings for the server"],"tags":["connection","kingbase","retry"],"backgroundTag":"connection-failed","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}