pgx icon indicating copy to clipboard operation
pgx copied to clipboard

Is pgxpool.Tx.{Commit,Rollback} check for tx.c redundant?

Open misha-drozd opened this issue 2 months ago • 1 comments

pgxpool.Tx.{Commit,Rollback} contain the following snippet (https://github.com/jackc/pgx/blob/v5.7.6/pgxpool/tx.go#L25):

	if tx.c != nil {
		tx.c.Release()
		tx.c = nil
	}

However the documentation for pgxpool.Conn.Release says

"However, it is safe to call Release multiple times. Subsequent calls after the first will be ignored."

and the implementation exits quickly if the Release was called already (https://github.com/jackc/pgx/blob/v5.7.6/pgxpool/conn.go#L20):

	if c.res == nil {
		return
	}

	conn := c.Conn()
	res := c.res
	c.res = nil

So is the checking in Tx redundant?

misha-drozd avatar Oct 21 '25 18:10 misha-drozd

It's not redundant. I just tried removing it and the tests hang.

jackc avatar Oct 22 '25 00:10 jackc