Skip to content

Instantly share code, notes, and snippets.

@johto
Created October 24, 2013 21:24
Show Gist options
  • Save johto/7145291 to your computer and use it in GitHub Desktop.
Save johto/7145291 to your computer and use it in GitHub Desktop.
panic from driver with a deferred txn rollback = bad time
package main
import (
_ "github.com/lib/pq"
"database/sql"
"time"
)
func reproduce(txn *sql.Tx) {
defer txn.Rollback()
var v int
err := txn.QueryRow("SELECT 1").Scan(&v)
if err != nil {
panic(err)
}
}
func main() {
db, err := sql.Open("postgres", "sslmode=disable")
if err != nil {
panic(err)
}
txn, err := db.Begin()
if err != nil {
panic(err)
}
go func() {
time.Sleep(5 * time.Second)
panic("stacktrace")
}()
reproduce(txn)
panic("not reached")
}
panic: stacktrace
goroutine 4 [running]:
main.func·001()
/home/marko/work/panic.go:30 +0x58
created by main.main
/home/marko/work/panic.go:31 +0xba
goroutine 1 [semacquire]:
sync.runtime_Semacquire(0x18360158)
/usr/local/go/src/pkg/runtime/zsema_linux_386.c:165 +0x32
sync.(*Mutex).Lock(0x18360154)
/usr/local/go/src/pkg/sync/mutex.go:66 +0xb6
database/sql.(*Tx).Rollback(0x1835c8a0, 0x0, 0x0)
/usr/local/go/src/pkg/database/sql/sql.go:877 +0x81
github.com/lib/pq.errRecover(0xb70d4e9c)
/home/marko/gopath/src/github.com/lib/pq/error.go:465 +0x358
github.com/lib/pq.(*conn).Query(0x18371000, 0x81a7fc8, 0x8, 0x8299c4c, 0x0, ...)
/home/marko/gopath/src/github.com/lib/pq/conn.go:455 +0x90
database/sql.(*DB).queryConn(0x1836c100, 0x18360150, 0x81da898, 0x81a7fc8, 0x8, ...)
/usr/local/go/src/pkg/database/sql/sql.go:728 +0x13a
database/sql.(*Tx).Query(0x1835c8a0, 0x81a7fc8, 0x8, 0x0, 0x0, ...)
/usr/local/go/src/pkg/database/sql/sql.go:1005 +0x94
database/sql.(*Tx).QueryRow(0x1835c8a0, 0x81a7fc8, 0x8, 0x0, 0x0, ...)
/usr/local/go/src/pkg/database/sql/sql.go:1012 +0x51
main.reproduce(0x1835c8a0)
/home/marko/work/panic.go:13 +0x70
main.main()
/home/marko/work/panic.go:32 +0xc8
goroutine 2 [syscall]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment