{"record":{"id":"af29f7ca98afbac9","repo":"jackc/pgx","slug":"pipeline-has-unsynced-requests","errorCode":null,"errorMessage":"pipeline has unsynced requests","messagePattern":"pipeline has unsynced requests","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgconn/pgconn.go","lineNumber":2949,"sourceCode":"}\n\nfunc (p *Pipeline) handleUnexpectedMessage(errStr string, msg pgproto3.BackendMessage) error {\n\tp.err = fmt.Errorf(\"pipeline: %s: received unexpected message type %T\", errStr, msg)\n\tp.conn.asyncClose()\n\treturn p.err\n}\n\n// Close closes the pipeline and returns the connection to normal mode.\nfunc (p *Pipeline) Close() error {\n\tif p.closed {\n\t\treturn p.err\n\t}\n\n\tp.closed = true\n\n\tif p.state.PendingSync() {\n\t\tp.conn.asyncClose()\n\t\tp.err = errors.New(\"pipeline has unsynced requests\")\n\t\tp.conn.contextWatcher.Unwatch()\n\t\tp.conn.unlock()\n\n\t\treturn p.err\n\t}\n\n\tfor p.state.ExpectedReadyForQuery() > 0 {\n\t\tresults, err := p.getResults()\n\t\tif err != nil {\n\t\t\tp.err = err\n\t\t\tvar pgErr *PgError\n\t\t\tif !errors.As(err, &pgErr) {\n\t\t\t\tp.conn.asyncClose()\n\t\t\t\tbreak\n\t\t\t}\n\t\t} else if results == nil {\n\t\t\t// getResults returns (nil, nil) when the request queue is exhausted but\n\t\t\t// ExpectedReadyForQuery is still > 0. This can happen when FATAL errors consume","sourceCodeStart":2931,"sourceCodeEnd":2967,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgconn/pgconn.go#L2931-L2967","documentation":"Pipeline.Close guard: the pipeline is being closed while it still has requests that were never followed by a Sync message, so their results were never read. To avoid leaving the connection in an ambiguous protocol state, pgx force-closes the underlying connection and returns this sentinel error.","triggerScenarios":"Thrown at pgconn/pgconn.go:2949 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Always call SendPipelineSync and consume all results before closing the pipeline","Drain outstanding results via GetResults/Exec before Close","Treat the connection as unusable afterwards — pgx has already async-closed it"],"exampleFix":null,"handlingStrategy":"validation","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"}