{"id":"3f7a60182479ad12","repo":"jackc/pgx","slug":"pgxpool-too-many-failed-attempts-acquiring-connec","errorCode":null,"errorMessage":"pgxpool: too many failed attempts acquiring connection; likely bug in PrepareConn, BeforeAcquire, or ShouldPing hook","messagePattern":"pgxpool: too many failed attempts acquiring connection; likely bug in PrepareConn, BeforeAcquire, or ShouldPing hook","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgxpool/pool.go","lineNumber":668,"sourceCode":"\t\tif p.prepareConn != nil {\n\t\t\tok, err := p.prepareConn(ctx, cr.conn)\n\t\t\tif !ok {\n\t\t\t\tres.Destroy()\n\t\t\t}\n\t\t\tif err != nil {\n\t\t\t\tif ok {\n\t\t\t\t\tres.Release()\n\t\t\t\t}\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tif !ok {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\n\t\treturn cr.getConn(p, res), nil\n\t}\n\treturn nil, errors.New(\"pgxpool: too many failed attempts acquiring connection; likely bug in PrepareConn, BeforeAcquire, or ShouldPing hook\")\n}\n\n// AcquireFunc acquires a [Conn] and calls f with that [Conn]. ctx will only affect the [Pool.Acquire]. It has no effect on the\n// call of f. The return value is either an error acquiring the [Conn] or the return value of f. The [Conn] is\n// automatically released after the call of f.\nfunc (p *Pool) AcquireFunc(ctx context.Context, f func(*Conn) error) error {\n\tconn, err := p.Acquire(ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer conn.Release()\n\n\treturn f(conn)\n}\n\n// AcquireAllIdle atomically acquires all currently idle connections. Its intended use is for health check and\n// keep-alive functionality. It does not update pool statistics.\nfunc (p *Pool) AcquireAllIdle(ctx context.Context) []*Conn {","sourceCodeStart":650,"sourceCodeEnd":686,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgxpool/pool.go#L650-L686","documentation":"Error \"pgxpool: too many failed attempts acquiring connection; likely bug in PrepareConn, BeforeAcquire, or ShouldPing hook\" thrown in jackc/pgx.","triggerScenarios":"Thrown at pgxpool/pool.go:668 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","schemaVersion":2}