Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UNHELPFUL ERROR MSG] obscure panic on closed connection #101

Closed
ngortheone opened this issue May 16, 2024 · 1 comment
Closed

[UNHELPFUL ERROR MSG] obscure panic on closed connection #101

ngortheone opened this issue May 16, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@ngortheone
Copy link

ngortheone commented May 16, 2024

I have accidentally closed the db connection before using it ( I had a stray defer db.Close() )

It took me a while to figure out what was causing the panic - there was no good error message to tell me what was the problem.
The panic message was looking like this:

 --- FAIL: TestCreateAndInitializeDatabase (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference
	panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x60 pc=0x574bfa]

goroutine 7 [running]:
testing.tRunner.func1.2({0x7533c0, 0xa5cbd0})
	/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.5.linux-amd64/src/testing/testing.go:1545 +0x238
testing.tRunner.func1()
	/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.5.linux-amd64/src/testing/testing.go:1548 +0x397
panic({0x7533c0?, 0xa5cbd0?})
	/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.5.linux-amd64/src/runtime/panic.go:914 +0x21f
modernc.org/libc.(*TLS).Alloc(0xc000181040?, 0x7f5f21600428?)
	/home/runner/go/pkg/mod/modernc.org/libc@v1.29.0/etc.go:248 +0x1a
modernc.org/sqlite/lib.logBadConnection(0x0, 0x79c9ed)
	/home/runner/go/pkg/mod/modernc.org/sqlite@v1.27.0/lib/sqlite_linux_amd64.go:14577 +0x32
modernc.org/sqlite/lib.Xsqlite3SafetyCheckSickOrOk(0x5dfdc5?, 0xc000102820?)
	/home/runner/go/pkg/mod/modernc.org/sqlite@v1.27.0/lib/sqlite_linux_amd64.go:14619 +0x38
modernc.org/sqlite/lib.sqlite3Close(0xc00018d870?, 0x7f5f21600428, 0x0)
	/home/runner/go/pkg/mod/modernc.org/sqlite@v1.27.0/lib/sqlite_linux_amd64.go:115266 +0x2e
modernc.org/sqlite/lib.Xsqlite3_close(...)
	/home/runner/go/pkg/mod/modernc.org/sqlite@v1.27.0/lib/sqlite_linux_amd64.go:115332
zombiezen.com/go/sqlite.(*Conn).Close(0xc000074370)
	/home/runner/go/pkg/mod/zombiezen.com/go/sqlite@v1.1.0/sqlite.go:212 +0x11d
panic({0x7533c0?, 0xa5cbd0?})
	/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.5.linux-amd64/src/runtime/panic.go:914 +0x21f
modernc.org/libc.(*TLS).Alloc(0xc00018daf0?, 0x443d71?)
	/home/runner/go/pkg/mod/modernc.org/libc@v1.29.0/etc.go:248 +0x1a
modernc.org/sqlite/lib.logBadConnection(0x0, 0x79c9ed)
	/home/runner/go/pkg/mod/modernc.org/sqlite@v1.27.0/lib/sqlite_linux_amd64.go:14577 +0x32
modernc.org/sqlite/lib.Xsqlite3SafetyCheckSickOrOk(0x578b7c?, 0x47b79a?)
	/home/runner/go/pkg/mod/modernc.org/sqlite@v1.27.0/lib/sqlite_linux_amd64.go:14619 +0x38
modernc.org/sqlite/lib.Xsqlite3SafetyCheckOk(0x7f5f21c003e0?, 0x0?)
	/home/runner/go/pkg/mod/modernc.org/sqlite@v1.27.0/lib/sqlite_linux_amd64.go:14605 +0x29
modernc.org/sqlite/lib.sqlite3LockAndPrepare(0x791eda?, 0x7f5f21600428, 0x7f5f21e00f20, 0x4137b2?, 0x0?, 0x7f5f20c00000?, 0x7f5f21c003e0, 0x0?)
	/home/runner/go/pkg/mod/modernc.org/sqlite@v1.27.0/lib/sqlite_linux_amd64.go:86092 +0x52
modernc.org/sqlite/lib.Xsqlite3_prepare_v3(...)
	/home/runner/go/pkg/mod/modernc.org/sqlite@v1.27.0/lib/sqlite_linux_amd64.go:86175
zombiezen.com/go/sqlite.(*Conn).prepare(0xc000074370, {0x791eda, 0x89}, 0x0)
	/home/runner/go/pkg/mod/zombiezen.com/go/sqlite@v1.1.0/sqlite.go:503 +0x275
zombiezen.com/go/sqlite.(*Conn).PrepareTransient(0x791f63?, {0x791eda?, 0x0?})
	/home/runner/go/pkg/mod/zombiezen.com/go/sqlite@v1.1.0/sqlite.go:480 +0x1f
zombiezen.com/go/sqlite/sqlitex.ExecuteTransient(0x784548?, {0x791eda, 0x89}, 0x5ad?)
	/home/runner/go/pkg/mod/zombiezen.com/go/sqlite@v1.1.0/sqlitex/exec.go:198 +0x3e
command-line-arguments.TestCreateAndInitializeDatabase(0xc0001569c0)
	/home/runner/work/phab-migration-tools/phab-migration-tools/bugz/db_test.go:16 +0xe6
testing.tRunner(0xc0001569c0, 0x7bb920)
	/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.5.linux-amd64/src/testing/testing.go:1595 +0xff
created by testing.(*T).Run in goroutine 1
	/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.5.linux-amd64/src/testing/testing.go:1648 +0x3ad
FAIL	command-line-arguments	0.006s
FAIL
Error: Process completed with exit code 1.

Is it possible to provide a more user-friendly panic message when a closed DB is being used?
For example put somewhere a check :

if closed {
    panic("The database connection was closed")
}
@zombiezen zombiezen added the enhancement New feature or request label May 24, 2024
@ngortheone
Copy link
Author

@zombiezen the 3255b67 commit does not really fix the problem, or at least I don't see how can it. It will only give an error on repeated close, but not when a closed connection is used to execute statements. The problem I had was that I was trying to perform a a select on the closed connection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants