pgx icon indicating copy to clipboard operation
pgx copied to clipboard

panic: BUG: slow write timer already active

Open kaber2 opened this issue 6 months ago • 2 comments

Describe the bug

Occasionally during heavy insert workloads, I get the aforementioned panic.

To Reproduce

I can't reliably reproduce it, I have 5 instances of a program running, each one running a heavy insert-only workload with many 10k inserts/sec total, using multiple parallel connections from a pool with CopyFrom. The workload only runs once every couple of weeks and sometimes it works fine, sometimes I receive the panic.

I have the following backtrace:

  goroutine 1 [chan receive]:    
          /home/xxx/go/pkg/mod/github.com/jackc/puddle/[email protected]/pool.go:76 +0x90    
  created by github.com/jackc/puddle/v2.(*Resource[...]).Destroy in goroutine 3709477    
          /home/xxx/go/pkg/mod/github.com/jackc/puddle/[email protected]/pool.go:688 +0x36      
  github.com/jackc/puddle/v2.(*Pool[...]).destroyAcquiredResource(0xc5facffc70, 0xcdd01eee80?)    
          /home/xxx/go/pkg/mod/github.com/jackc/puddle/[email protected]/pool.go:708 +0x1f      
  github.com/jackc/puddle/v2.(*Pool[...]).destructResourceValue(0xcdfb311c20, 0xccca96c008?)    
          /home/xxx/go/pkg/mod/github.com/jackc/pgx/[email protected]/pgxpool/pool.go:259 +0x9a      
  github.com/jackc/pgx/v5/pgxpool.NewWithConfig.func2(0xcd7c8f2a10)    
          /home/xxx/go/pkg/mod/github.com/jackc/pgx/[email protected]/conn.go:303 +0x31      
  github.com/jackc/pgx/v5.(*Conn).Close(0x3ae5dd0?, {0x3ae5eb0?, 0xce0201cd20?})    
          /home/xxx/go/pkg/mod/github.com/jackc/pgx/[email protected]/pgconn/pgconn.go:663 +0x185      
  github.com/jackc/pgx/v5/pgconn.(*PgConn).Close(0xc8836bd208, {0x3ae5eb0, 0xce0201cd20})    
          /home/xxx/go/pkg/mod/github.com/jackc/pgx/[email protected]/pgconn/pgconn.go:1875 +0xa6      
  github.com/jackc/pgx/v5/pgconn.(*PgConn).flushWithPotentialWriteReadDeadlock(0xc8836bd208)    
          /home/xxx/go/pkg/mod/github.com/jackc/pgx/[email protected]/pgconn/pgconn.go:1856                                                                                                                                 
  github.com/jackc/pgx/v5/pgconn.(*PgConn).enterPotentialWriteReadDeadlock(...)    
  goroutine 3708813 [running]:    
  panic: BUG: slow write timer already active    

Version

  • Go: go version go1.24.0 linux/amd64
  • PostgreSQL: PostgreSQL 17.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3), 64-bit
  • pgx: github.com/jackc/pgx/v5 v5.7.1

kaber2 avatar May 25 '25 07:05 kaber2

It must be a race. I can reproducibly cause this panic, but when I add an atomic integer to sequence the calls to pgx, it disappears.

gm42 avatar Aug 04 '25 09:08 gm42

Any chance someone could post a reproduction case here?

jackc avatar Aug 09 '25 14:08 jackc