{"record":{"id":"8794bd02eecc7863","repo":"iflytek/astron-agent","slug":"begin-tenant-bootstrap-transaction-failed-w","errorCode":null,"errorMessage":"begin tenant bootstrap transaction failed: %w","messagePattern":"begin tenant bootstrap transaction failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"core/tenant/tools/database/bootstrap_credentials.go","lineNumber":59,"sourceCode":") bootstrapRowScanner {\n\treturn transaction.transaction.QueryRowContext(ctx, query, args...)\n}\n\nfunc reconcileTenantBootstrap(\n\tclient *sql.DB,\n\tcredentials config.TenantBootstrapCredentials,\n) error {\n\tif client == nil {\n\t\treturn errors.New(\"mysql client is nil\")\n\t}\n\tif err := credentials.Validate(); err != nil {\n\t\treturn fmt.Errorf(\"invalid tenant bootstrap credentials: %w\", err)\n\t}\n\n\tctx := context.Background()\n\ttransaction, err := client.BeginTx(ctx, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"begin tenant bootstrap transaction failed: %w\", err)\n\t}\n\tdefer func() {\n\t\t_ = transaction.Rollback()\n\t}()\n\n\tif err := reconcileTenantBootstrapTransaction(\n\t\tctx,\n\t\tsqlBootstrapTransaction{transaction: transaction},\n\t\tcredentials,\n\t); err != nil {\n\t\treturn err\n\t}\n\tif err := transaction.Commit(); err != nil {\n\t\treturn fmt.Errorf(\"commit tenant bootstrap transaction failed: %w\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/tenant/tools/database/bootstrap_credentials.go#L41-L77","documentation":"reconcileTenantBootstrap opens a MySQL transaction via client.BeginTx to reconcile the bootstrap app/credentials; if the transaction cannot even be started (DB unreachable, too many connections, server shutdown) the error is wrapped as 'begin tenant bootstrap transaction failed'.","triggerScenarios":"initializeMysqlClient -> reconcileTenantBootstrap while MySQL is down, unreachable, refusing connections, or has exhausted max_connections so BEGIN fails.","commonSituations":"MySQL container not yet ready during service startup; wrong DSN/host in tenant service config; connection pool exhausted by leaked transactions; MySQL restarted mid-deploy.","solutions":["Verify MySQL is reachable (docker compose ps, mysql -h ... -e 'SELECT 1') and the tenant service DSN/host/port are correct.","Retry after MySQL is ready — add readiness gating or backoff so initializeMysqlClient does not race DB startup.","Check max_connections and for leaked transactions/connection pool misconfiguration in the tenant service.","Inspect the wrapped cause (%w chain) to distinguish network refusal from auth or pool errors."],"exampleFix":"// before\ntransaction, err := client.BeginTx(ctx, nil)\nif err != nil { return fmt.Errorf(\"begin tenant bootstrap transaction failed: %w\", err) }\n// after: gate on DB readiness with retry\nif err := waitUntilMySQLReady(ctx, client, 30*time.Second); err != nil {\n    return fmt.Errorf(\"mysql not ready for bootstrap: %w\", err)\n}\ntransaction, err := client.BeginTx(ctx, nil)\nif err != nil { return fmt.Errorf(\"begin tenant bootstrap transaction failed: %w\", err) }","handlingStrategy":"retry","validationCode":"if err := client.Ping(); err != nil {\n    return fmt.Errorf(\"mysql unreachable before bootstrap: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"for attempt := 0; attempt < 5; attempt++ {\n    err := reconcileTenantBootstrap(client, creds)\n    if err == nil { break }\n    if strings.Contains(err.Error(), \"begin tenant bootstrap transaction failed\") {\n        time.Sleep(time.Duration(attempt+1) * 2 * time.Second)\n        continue\n    }\n    return err\n}","preventionTips":["Gate service startup on MySQL readiness (depends_on healthcheck / readiness probe).","Set sane pool limits so bootstrap never fights max_connections.","Use short-lived bootstrap transactions to avoid idle disconnects."],"tags":["go","mysql","transaction","connectivity"],"backgroundTag":"connection-refused","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}