jackc / jackc/pgx

panic: BUG: slow write timer already active

Open
#2,332 22 comments 6 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
14.3k
Forks
1.1k
Avg merge
6d 9h
Merged PRs (30d)
11

Description

**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/v2@v2.2.2/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/v2@v2.2.2/pool.go:688 +0x36
github.com/jackc/puddle/v2.(*Pool[...]).destroyAcquiredResource(0xc5facffc70, 0xcdd01eee80?)
/home/xxx/go/pkg/mod/github.com/jackc/puddle/v2@v2.2.2/pool.go:708 +0x1f
github.com/jackc/puddle/v2.(*Pool[...]).destructResourceValue(0xcdfb311c20, 0xccca96c008?)
/home/xxx/go/pkg/mod/github.com/jackc/pgx/v5@v5.7.1/pgxpool/pool.go:259 +0x9a
github.com/jackc/pgx/v5/pgxpool.NewWithConfig.func2(0xcd7c8f2a10)
/home/xxx/go/pkg/mod/github.com/jackc/pgx/v5@v5.7.1/conn.go:303 +0x31
github.com/jackc/pgx/v5.(*Conn).Close(0x3ae5dd0?, {0x3ae5eb0?, 0xce0201cd20?})
/home/xxx/go/pkg/mod/github.com/jackc/pgx/v5@v5.7.1/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/v5@v5.7.1/pgconn/pgconn.go:1875 +0xa6
github.com/jackc/pgx/v5/pgconn.(*PgConn).flushWithPotentialWriteReadDeadlock(0xc8836bd208)
/home/xxx/go/pkg/mod/github.com/jackc/pgx/v5@v5.7.1/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

Contributor guide

Open the contributing guide

Research direction

Start in pgconn/pgconn.go at flushWithPotentialWriteReadDeadlock and enterPotentialWriteReadDeadlock, then inspect the pgxpool/pool.go resource-destruction path shown in the backtrace. Reproduce the panic under concurrent CopyFrom and connection-pool workloads if possible, and add regression coverage that confirms the slow-write timer cannot be activated twice.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.