Pgx: conn busy

Created on 19 Sep 2019  Â·  1Comment  Â·  Source: jackc/pgx

Why is it not creating a new connection, but using the old one?

I expected the Acquire function to return a free connection to me, but instead I get the same thing.

func (p *Pg) sendBatch(batch *pgx.Batch) error {
    conn, err := p.pool.Acquire(context.Background())
    log.Println(conn.Conn().PgConn().PID())
    if err != nil {
        return err
    }
    defer conn.Release()

    br := conn.SendBatch(context.Background(), batch)
    _, err = br.Exec()
    log.Println(err)
    return err
}

output:

db.go:77: 19320
db.go:88: <nil>
db.go:77: 19320
db.go:88: conn busy
db.go:77: 19320
db.go:88: conn busy

Most helpful comment

Batch operations must be closed before the connection can be used again. Unfortunately, that wasn't explicit in the docs. I've corrected that: e16bfa9af53e1ba5c007bdd7cce89cd5e1455518

The pool expects that the connection was returned in a idle state so it keeps returning the broken connection.

Call br.Close() and the problem will be resolved.

Also, I recommend calling SendBatch on the pool instead of acquiring and releasing a conn manually.

>All comments

Batch operations must be closed before the connection can be used again. Unfortunately, that wasn't explicit in the docs. I've corrected that: e16bfa9af53e1ba5c007bdd7cce89cd5e1455518

The pool expects that the connection was returned in a idle state so it keeps returning the broken connection.

Call br.Close() and the problem will be resolved.

Also, I recommend calling SendBatch on the pool instead of acquiring and releasing a conn manually.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mrdulin picture mrdulin  Â·  4Comments

danclive picture danclive  Â·  6Comments

badoet picture badoet  Â·  10Comments

deletexl picture deletexl  Â·  4Comments

skipcloud picture skipcloud  Â·  4Comments