Skip to content

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

@misha-drozd

Description

@misha-drozd

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions