{"record":{"id":"d4f043631903b9ed","repo":"jackc/pgx","slug":"failed-to-deallocate-cached-statement-s-w","errorCode":null,"errorMessage":"failed to deallocate cached statement(s): %w","messagePattern":"failed to deallocate cached statement\\(s\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"conn.go","lineNumber":1462,"sourceCode":"\tvar invalidatedStatements []*pgconn.StatementDescription\n\tif c.statementCache != nil {\n\t\tinvalidatedStatements = c.statementCache.GetInvalidated()\n\t}\n\n\tif len(invalidatedStatements) == 0 {\n\t\treturn nil\n\t}\n\n\tpipeline := c.pgConn.StartPipeline(ctx)\n\tdefer pipeline.Close()\n\n\tfor _, sd := range invalidatedStatements {\n\t\tpipeline.SendDeallocate(sd.Name)\n\t}\n\n\terr := pipeline.Sync()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to deallocate cached statement(s): %w\", err)\n\t}\n\n\terr = pipeline.Close()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to deallocate cached statement(s): %w\", err)\n\t}\n\n\tc.statementCache.RemoveInvalidated()\n\tfor _, sd := range invalidatedStatements {\n\t\tdelete(c.preparedStatements, sd.Name)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":1444,"sourceCodeEnd":1477,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/conn.go#L1444-L1477","documentation":"After query execution, pgx tried to deallocate cached statements that had been invalidated (e.g. by a schema change), but the pipeline Sync or Close failed. The underlying pipeline error is wrapped with %w; cached statements may remain allocated server-side.","triggerScenarios":"Thrown at conn.go:1462 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Unwrap to inspect the underlying pipeline error","If the connection is healthy, retry the operation that triggered invalidation so cleanup re-runs","If the connection is closing or dead, the server cleans up statements on disconnect — safe to ignore"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}