Skip to content

Raw() does not return if connection is closed #2346

Open
@horgh

Description

@horgh

Describe the bug
I am accessing a connection via Raw() using the stdlib compatibility layer in order to close a connection that is in a bad state. I discovered that if I am in a transaction, Raw() does not return, and instead hangs. If I rollback the transaction before calling Raw(), this does not happen.

I'm not sure if this is a bug in pgx or maybe database/sql.

To Reproduce
I put a reproducer here: https://gist.github.com/horgh/e3ba60ecc20f8cf2bf7e4d795c336350

The reproducer includes a Rollback() which avoids the hang. If you comment out the Rollback() on line 69 you will see it hang. There are a few other comments in there that might be of interest.

Please run your example with the race detector enabled. For example, go run -race main.go or go test -race.

Expected behavior
Raw() should return.

Actual behavior
Raw() does not return

Version

  • Go: $ go version -> go version go1.24.4 linux/amd64
  • PostgreSQL: $ psql --no-psqlrc --tuples-only -c 'select version()' -> PostgreSQL 16.9 (Ubuntu 16.9-1.pgdg24.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0, 64-bit
  • pgx: $ grep 'github.com/jackc/pgx/v[0-9]' go.mod -> v5.7.5

Additional context
I am closing the connection to try to work around #2223

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions