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

spanner: nil reference if a transaction is retried due to a Session not found error #10385

Closed
olavloite opened this issue Jun 17, 2024 · 0 comments · Fixed by #10386
Closed
Assignees
Labels
api: spanner Issues related to the Spanner API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@olavloite
Copy link
Contributor

--- FAIL: TestEmptyQueryAbortedTwice (0.01s)
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=0x0 pc=0xf04b1a]

goroutine 11 [running]:
testing.tRunner.func1.2({0x114ed80, 0x1f20880})
	/opt/hostedtoolcache/go/1.20.14/x64/src/testing/testing.go:1526 +0x24e
testing.tRunner.func1()
	/opt/hostedtoolcache/go/1.20.14/x64/src/testing/testing.go:1529 +0x39f
panic({0x114ed80, 0x1f20880})
	/opt/hostedtoolcache/go/1.20.14/x64/src/runtime/panic.go:884 +0x213
cloud.google.com/go/spanner.(*sessionPool).take(0x0, {0x1532e08, 0xc00012e000})
	/home/runner/go/pkg/mod/cloud.google.com/go/[email protected]/session.go:1040 +0x9a
cloud.google.com/go/spanner.(*ReadWriteTransaction).begin(0xc0005a2f00, {0x1532e08, 0xc00012e000})
	/home/runner/go/pkg/mod/cloud.google.com/go/[email protected]/transaction.go:1501 +0x346
cloud.google.com/go/spanner.NewReadWriteStmtBasedTransactionWithOptions({0x1532e08, 0xc00012e000}, 0xc000b419e0, {{0x0, 0x0}, {0x0, 0x0}, 0x0, 0x0, 0x0})
	/home/runner/go/pkg/mod/cloud.google.com/go/[email protected]/transaction.go:1757 +0x385
github.com/googleapis/go-sql-spanner.(*conn).BeginTx(0xc001e331e0, {0x1532e08?, 0xc00012e000}, {0xc001419928?, 0x3d?})
	/home/runner/work/go-sql-spanner/go-sql-spanner/driver.go:976 +0x4fb
database/sql.ctxDriverBegin({0x1532e08, 0xc00012e000}, 0xc001419cb0, {0x1530fd0, 0xc001e331e0})
	/opt/hostedtoolcache/go/1.20.14/x64/src/database/sql/ctxutil.go:104 +0x7b
database/sql.(*DB).beginDC.func1()
	/opt/hostedtoolcache/go/1.20.14/x64/src/database/sql/sql.go:1868 +0xc5
database/sql.withLock({0x152e318, 0xc0000b2090}, 0xc001419a38)
	/opt/hostedtoolcache/go/1.20.14/x64/src/database/sql/sql.go:3405 +0x8c
database/sql.(*DB).beginDC(0xc004577ee0, {0x1532e08, 0xc00012e000}, 0xc0000b2090, 0xc00059cf20, 0xc001419b08?)
	/opt/hostedtoolcache/go/1.20.14/x64/src/database/sql/sql.go:1864 +0xcf
database/sql.(*DB).begin(0x0?, {0x1532e08, 0xc00012e000}, 0xf973a0?, 0x10?)
	/opt/hostedtoolcache/go/1.20.14/x64/src/database/sql/sql.go:1857 +0x94
database/sql.(*DB).BeginTx.func1(0x8a?)
	/opt/hostedtoolcache/go/1.20.14/x64/src/database/sql/sql.go:1836 +0x45
database/sql.(*DB).retry(0x1523a00?, 0xc001419b90)
	/opt/hostedtoolcache/go/1.20.14/x64/src/database/sql/sql.go:1538 +0x[47](https://github.com/googleapis/go-sql-spanner/actions/runs/9548744099/job/26316634938?pr=256#step:4:48)
database/sql.(*DB).BeginTx(0x1540e88?, {0x1532e08?, 0xc00012e000?}, 0x456a08?)
	/opt/hostedtoolcache/go/1.20.14/x64/src/database/sql/sql.go:1835 +0x8a
github.com/googleapis/go-sql-spanner.testRetryReadWriteTransactionWithQuery(0xc000[50](https://github.com/googleapis/go-sql-spanner/actions/runs/9548744099/job/26316634938?pr=256#step:4:51)3a00, 0x13fcfb0, 0x0, 0xffffffffffffffff, 0x3, 0x1, 0x0, {0x0?, 0x0})
	/home/runner/work/go-sql-spanner/go-sql-spanner/aborted_transactions_test.go:369 +0x132
github.com/googleapis/go-sql-spanner.testRetryReadWriteTransactionWithQueryWithRetrySuccess(...)
	/home/runner/work/go-sql-spanner/go-sql-spanner/aborted_transactions_test.go:350
github.com/googleapis/go-sql-spanner.TestEmptyQueryAbortedTwice(0xc000503380?)
	/home/runner/work/go-sql-spanner/go-sql-spanner/aborted_transactions_test.go:169 +0x3d
testing.tRunner(0xc000503a00, 0x13fcfb8)
	/opt/hostedtoolcache/go/1.20.14/x64/src/testing/testing.go:1[57](https://github.com/googleapis/go-sql-spanner/actions/runs/9548744099/job/26316634938?pr=256#step:4:58)6 +0x10b
created by testing.(*T).Run
	/opt/hostedtoolcache/go/1.20.14/x64/src/testing/testing.go:1629 +0x3ea
exit status 2
FAIL	github.com/googleapis/go-sql-spanner	0.373s
Error: Process completed with exit code 1.
@olavloite olavloite added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Jun 17, 2024
@olavloite olavloite self-assigned this Jun 17, 2024
@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label Jun 17, 2024
olavloite added a commit that referenced this issue Jun 17, 2024
The Spanner client library could panic if specifically the following
situation would occur:
1. Create a StmtBasedReadWriteTransaction
2. Only execute mutations, so that an explicit BeginTransaction
   RPC is required.
3. The BeginTransaction RPC returns "Session not found"
4. The client library tries to get a new session from the pool.

Step 4 above would panic, because the client library did not set the
readOnlyTransaction.sp field for StmtBasedReadWriteTransactions.

Fixes #10385
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant