{"record":{"id":"1d3b5c0d40fb9e0b","repo":"jackc/pgx","slug":"conn-closed","errorCode":null,"errorMessage":"conn closed","messagePattern":"conn closed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgconn/errors.go","lineNumber":100,"sourceCode":"type perDialConnectError struct {\n\taddress          string\n\toriginalHostname string\n\terr              error\n}\n\nfunc (e *perDialConnectError) Error() string {\n\treturn fmt.Sprintf(\"%s (%s): %s\", e.address, e.originalHostname, e.err.Error())\n}\n\nfunc (e *perDialConnectError) Unwrap() error {\n\treturn e.err\n}\n\n// ErrConnClosed is returned (possibly wrapped) when an operation is attempted\n// on a connection that the driver has already closed, e.g. because a prior\n// query was cancelled mid-flight or the underlying socket went away. Use\n// errors.Is to test for it, since it shows up wrapped inside connLockError.\nvar ErrConnClosed = errors.New(\"conn closed\")\n\ntype connLockError struct {\n\tstatus string\n}\n\nfunc (e *connLockError) SafeToRetry() bool {\n\treturn true // a lock failure by definition happens before the connection is used.\n}\n\nfunc (e *connLockError) Error() string {\n\treturn e.status\n}\n\nfunc (e *connLockError) Unwrap() error {\n\tif e.status == \"conn closed\" {\n\t\treturn ErrConnClosed\n\t}\n\treturn nil","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgconn/errors.go#L82-L118","documentation":"Sentinel error (ErrConnClosed) signaling that the operation was attempted on a PgConn the driver has already closed — e.g. after a cancelled query, a network failure, or an explicit Close. The guard is a simple closed-flag check; the stale connection handle is the faulty input. It is frequently wrapped, so test with errors.Is.","triggerScenarios":"Thrown at pgconn/errors.go:100 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not reuse a connection after Close or a fatal error; obtain a fresh one (or from the pool)","Detect it with errors.Is(err, pgconn.ErrConnClosed)","With pgxpool, release dead connections and re-acquire instead of caching them"],"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"}