Panic in chunkreader.go:61
- Dominant language
- Go
- Stars
- 14.3k
- Forks
- 1.1k
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 11
Description
Hi, jackc.
We have a high load application. After upgrading from pgx/v4 4.13.0 to pgx/v4 4.14.0 we started to get panic. It reproduces only in high load and has low probability.
Stack trace is below
```
panic: runtime error: slice bounds out of range [1629:1625]
goroutine 3558588163 [running]:
panic({0xe42dc0, 0xc0634369c0})
/-S/contrib/go/_std/src/runtime/panic.go:1147 +0x3a8 fp=0xc0082b1978 sp=0xc0082b18b8 pc=0x28658e8
runtime.goPanicSliceB(0x65d, 0x659)
/-S/contrib/go/_std/src/runtime/panic.go:118 +0x75 fp=0xc0082b19b8 sp=0xc0082b1978 pc=0x2862e35
github.com/jackc/chunkreader/v2.(*ChunkReader).Next(0xc0a8b35a40, 0x5)
/-S/vendor/github.com/jackc/chunkreader/v2/chunkreader.go:61 +0x365 fp=0xc0082b1a28 sp=0xc0082b19b8 pc=0x2c18a05
github.com/jackc/pgproto3/v2.(*Frontend).Receive(0xc001281800)
/-S/vendor/github.com/jackc/pgproto3/v2/frontend.go:82 +0x129 fp=0xc0082b1ab8 sp=0xc0082b1a28 pc=0x2c20e49
a.yandex-team.ru/mds/s3/goose/internal/db/postgres/pgcommon.(*frontendPatcher).Receive(0x5)
/-S/mds/s3/goose/internal/db/postgres/pgcommon/connect.go:105 +0x22 fp=0xc0082b1ad0 sp=0xc0082b1ab8 pc=0x3049842
github.com/jackc/pgconn.(*PgConn).peekMessage(0xc0427762c0)
/-S/vendor/github.com/jackc/pgconn/pgconn.go:466 +0x136 fp=0xc0082b1b38 sp=0xc0082b1ad0 pc=0x2c673f6
github.com/jackc/pgconn.(*PgConn).receiveMessage(0xc0427762c0)
/-S/vendor/github.com/jackc/pgconn/pgconn.go:486 +0x25 fp=0xc0082b1ba0 sp=0xc0082b1b38 pc=0x2c67505
github.com/jackc/pgconn.(*MultiResultReader).receiveMessage(0xc0427763d8)
/-S/vendor/github.com/jackc/pgconn/pgconn.go:1306 +0x28 fp=0xc0082b1bf0 sp=0xc0082b1ba0 pc=0x2c6e188
github.com/jackc/pgconn.(*MultiResultReader).NextResult(0xc0427763d8)
/-S/vendor/github.com/jackc/pgconn/pgconn.go:1331 +0x56 fp=0xc0082b1d18 sp=0xc0082b1bf0 pc=0x2c6e616
github.com/jackc/pgx/v4.(*Conn).Query(0xc062f86100, {0x1339c68, 0xc060db2330}, {0xc049515500, 0x92d}, {0xc0397372c0, 0xc03ef35260, 0xc03ef35260})
/-S/vendor/github.com/jackc/pgx/v4/conn.go:612 +0x35e fp=0xc0082b1e88 sp=0xc0082b1d18 pc=0x2d23b3e
github.com/jackc/pgx/v4/stdlib.(*Conn).QueryContext(0xc04eb80d80, {0x1339c68, 0xc060db2330}, {0xc049515500, 0x92d}, {0xc078bdb5f0, 0x5, 0x5})
/-S/vendor/github.com/jackc/pgx/v4/stdlib/sql.go:415 +0x1e5 fp=0xc0082b1f30 sp=0xc0082b1e88 pc=0x3044da5
a.yandex-team.ru/mds/s3/goose/internal/db/postgres/clusters.(*clusterConn).QueryContext.func1()
/-S/mds/s3/goose/internal/db/postgres/clusters/cluster_connector.go:259 +0xaf fp=0xc0082b1fe0 sp=0xc0082b1f30 pc=0x306e44f
runtime.goexit()
/-S/contrib/go/_std/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc0082b1fe8 sp=0xc0082b1fe0 pc=0x28994c1
created by a.yandex-team.ru/mds/s3/goose/internal/db/postgres/clusters.(*clusterConn).QueryContext
/-S/mds/s3/goose/internal/db/postgres/clusters/cluster_connector.go:257 +0x2d1
```
And two extra cases with same stack traces
```
panic: runtime error: slice bounds out of range [1337:1334]
panic: runtime error: slice bounds out of range [6998:6995]
```
May be this issue is related to https://github.com/jackc/pgx/issues/1138, I don't know.
Contributor guide
Research direction
Start at vendor/github.com/jackc/chunkreader/v2/chunkreader.go:61, then trace the call through pgproto3/v2/frontend.go:82 and pgconn/pgconn.go. Compare behavior between pgx/v4 4.13.0 and 4.14.0 under high load; done means the reported slice-bounds panic no longer occurs in the affected query path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100