Skip to content

Commit

Permalink
pgconn: check if pipeline i closed in Sync/GetResults
Browse files Browse the repository at this point in the history
Otherwise there will be a nil pointer exception accessing the conn
  • Loading branch information
jameshartig committed Dec 22, 2023
1 parent 9ab9e3c commit 83646c0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pgconn/pgconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2053,6 +2053,13 @@ func (p *Pipeline) Flush() error {

// Sync establishes a synchronization point and flushes the queued requests.
func (p *Pipeline) Sync() error {
if p.closed {
if p.err != nil {
return p.err
}
return errors.New("pipeline closed")
}

p.conn.frontend.SendSync(&pgproto3.Sync{})
err := p.Flush()
if err != nil {
Expand All @@ -2069,6 +2076,13 @@ 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
}
Expand Down

0 comments on commit 83646c0

Please sign in to comment.