Skip to content

panic when a Context is cancelled #614

Closed
@blinsay

Description

@blinsay

I've been using SELECT FOR UPDATE in a transaction and wanted to put a timeout on the transaction so that callers wouldn't get blocked. I've been seeing a runtime error: slice bounds out of range panic in rows.Next that smells like some invalid data being returned.

2017/05/22 15:27:49 http: panic serving [::1]:57542: runtime error: slice bounds out of range
goroutine 52 [running]:
net/http.(*conn).serve.func1(0xc4201c2960)
	/usr/local/go/src/net/http/server.go:1721 +0xd0
panic(0x17537a0, 0x1c2f970)
	/usr/local/go/src/runtime/panic.go:489 +0x2cf
github.com/path/to/project/vendor/github.com/lib/pq.(*conn).errRecover(0xc4200d6b00, 0xc42013f188)
	/home/go/src/github.com/path/to/project/vendor/github.com/lib/pq/error.go:482 +0x505
panic(0x17537a0, 0x1c2f970)
	/usr/local/go/src/runtime/panic.go:489 +0x2cf
github.com/path/to/project/vendor/github.com/lib/pq.(*rows).Next(0xc42054a0a0, 0xc42054a280, 0xa, 0xa, 0x0, 0x0)
	/home/go/src/github.com/path/to/project/vendor/github.com/lib/pq/conn.go:1403 +0x5e9
database/sql.(*Rows).nextLocked(0xc42054c100, 0xc42013f1e0)
	/usr/local/go/src/database/sql/sql.go:2149 +0x6c
database/sql.(*Rows).Next.func1()
	/usr/local/go/src/database/sql/sql.go:2134 +0x3c
database/sql.withLock(0x1c04f80, 0xc42054c130, 0xc42013f220)
	/usr/local/go/src/database/sql/sql.go:2545 +0x65
database/sql.(*Rows).Next(0xc42054c100, 0x18a39e0)
	/usr/local/go/src/database/sql/sql.go:2135 +0x83

The panic starts here and only occurs if I get the context to cancel at exaaactly the right time. Adding print statements or changing my context timeout changes how reliably I can reproduce it.

I'm running against Postgres 9.6.2 and have lib/pq at 2704adc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions