From 22fe50149b6f723af4d77c71244d54964bd14e03 Mon Sep 17 00:00:00 2001 From: James Hartig Date: Fri, 22 Dec 2023 14:19:09 -0600 Subject: [PATCH] pgconn: check if pipeline i closed in Sync/GetResults Otherwise there will be a nil pointer exception accessing the conn --- pgconn/pgconn.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pgconn/pgconn.go b/pgconn/pgconn.go index fe9e37779..d5a67beaf 100644 --- a/pgconn/pgconn.go +++ b/pgconn/pgconn.go @@ -2076,10 +2076,21 @@ func (p *Pipeline) Sync() error { // *PipelineSync. If an ErrorResponse is received from the server, results will be nil and err will be a *PgError. If no // results are available, results and err will both be nil. func (p *Pipeline) GetResults() (results any, err error) { + if p.closed { + if p.err != nil { + return nil, p.err + } + return nil, errors.New("pipeline closed") + } + if p.expectedReadyForQueryCount == 0 { return nil, nil } + return p.getResults() +} + +func (p *Pipeline) getResults() (results any, err error) { for { msg, err := p.conn.receiveMessage() if err != nil { @@ -2166,6 +2177,7 @@ func (p *Pipeline) Close() error { if p.closed { return p.err } + p.closed = true if p.pendingSync { @@ -2178,7 +2190,7 @@ func (p *Pipeline) Close() error { } for p.expectedReadyForQueryCount > 0 { - _, err := p.GetResults() + _, err := p.getResults() if err != nil { p.err = err var pgErr *PgError