Skip to content

Commit f4d3fb0

Browse files
committed
pgconn: improve comment explaining nil, nil path in Pipeline.Close
Expand the comment on the results == nil guard in Pipeline.Close() to explain exactly when and why getResults() returns (nil, nil): When the server sends FATAL errors that consume queued request slots (e.g. Prepare, Sync) without ever sending ReadyForQuery, the request event queue is exhausted while expectedReadyForQueryCount remains > 0. ExtractFrontRequestType() returns pipelineNil, getResults() returns (nil, nil), and without this guard the loop would spin indefinitely.
1 parent c3ede46 commit f4d3fb0

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

pgconn/pgconn.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2836,8 +2836,11 @@ func (p *Pipeline) Close() error {
28362836
break
28372837
}
28382838
} else if results == nil {
2839-
// No more results available but we haven't received all expected ReadyForQuery messages.
2840-
// This means the connection is in a bad state (e.g. server closed the connection).
2839+
// getResults returns (nil, nil) when the request queue is exhausted (pipelineNil) but
2840+
// ExpectedReadyForQuery is still > 0. This happens when the server sends FATAL errors that
2841+
// consume queued request slots (e.g. Prepare, Sync) without ever sending ReadyForQuery --
2842+
// so expectedReadyForQueryCount is never decremented. Without this check the loop would spin
2843+
// indefinitely because there are no more requests to issue and no ReadyForQuery to receive.
28412844
p.conn.asyncClose()
28422845
if p.err == nil {
28432846
p.err = errors.New("pipeline: no more results but expected ReadyForQuery")

0 commit comments

Comments
 (0)