{"record":{"id":"b8b3c9d76e55b97f","repo":"SigNoz/signoz","slug":"internal-b8b3c9","errorCode":"internal","errorMessage":"failed to start transaction","messagePattern":"failed to start transaction","errorType":"error_code","errorClass":"errors.base","httpStatus":500,"severity":"error","filePath":"pkg/modules/user/impluser/store.go","lineNumber":148,"sourceCode":"\n\terr := store.\n\t\tsqlstore.\n\t\tBunDBCtx(ctx).\n\t\tNewSelect().\n\t\tModel(&users).\n\t\tWhere(\"org_id = ?\", orgID).\n\t\tScan(ctx)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn users, nil\n}\n\nfunc (store *store) DeleteUser(ctx context.Context, orgID string, id string) error {\n\ttx, err := store.sqlstore.BunDB().BeginTx(ctx, nil)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, errors.TypeInternal, errors.CodeInternal, \"failed to start transaction\")\n\t}\n\n\tdefer func() {\n\t\t_ = tx.Rollback()\n\t}()\n\n\t// get the password id\n\n\tvar password types.FactorPassword\n\terr = tx.NewSelect().\n\t\tModel(&password).\n\t\tWhere(\"user_id = ?\", id).\n\t\tScan(ctx)\n\tif err != nil && err != sql.ErrNoRows {\n\t\treturn errors.Wrapf(err, errors.TypeInternal, errors.CodeInternal, \"failed to delete password\")\n\t}\n\n\t// delete reset password request","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/modules/user/impluser/store.go#L130-L166","documentation":"DeleteUser starts a multi-statement transaction by calling BeginTx; if the database cannot open a new transaction this internal error is returned before any user data is touched. Common root causes are lost connections, exhausted connection pools, or a canceled/invalid context. Because BeginTx acquires a connection from the pool, pool starvation is a frequent culprit.","triggerScenarios":"Calling DeleteUser when the DB connection pool is saturated, the server restarted/closed connections, ctx is already canceled, or the database is in recovery/read-only mode.","commonSituations":"Connection pool max size too small for concurrent delete requests, Postgres restart or failover, long-running transactions holding all pool connections, k8s liveness probes canceling request contexts.","solutions":["Inspect wrapped error: driver.ErrBadConn or context.Canceled points to pool/context issues","Increase or tune connection pool settings and idle timeouts on the sqlstore","Retry the DeleteUser call with backoff if the error is transient connectivity","Verify DB is accepting writes (not in recovery/read-only)"],"exampleFix":"// before\nerr := store.DeleteUser(ctx, orgID, userID)\n\n// after\nif err := store.DeleteUser(ctx, orgID, userID); err != nil {\n    if strings.Contains(err.Error(), \"cannot begin transaction\") {\n        time.Sleep(200 * time.Millisecond)\n        err = store.DeleteUser(ctx, orgID, userID) // one retry\n    }\n}","handlingStrategy":"retry","validationCode":"if ctx.Err() != nil { return ctx.Err() }\nif err := store.sqlstore.BunDB().PingContext(ctx); err != nil { return err }","typeGuard":"func isBeginTxFailure(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"cannot begin transaction\")\n}","tryCatchPattern":"err := firstAttempt\nif isBeginTxFailure(err) {\n    time.Sleep(200*time.Millisecond)\n    err = store.DeleteUser(ctx, orgID, id)\n}\nreturn err","preventionTips":["Size the connection pool for peak concurrency; alert on pool wait times","Always pass request-scoped contexts with adequate deadlines","Monitor for transaction leaks holding pool connections"],"tags":["database","transaction","connection-pool","user-management"],"backgroundTag":"db-transaction-begin-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}