Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: Panic when closing DB while other goroutines doing reads #1987

Merged
merged 1 commit into from
Aug 4, 2023

Conversation

fatelei
Copy link
Contributor

@fatelei fatelei commented Aug 4, 2023

fix: Panic when closing DB while other goroutines doing reads

Problem

fix #1923

Solution

when db close, set closed flag firstly

@CLAassistant
Copy link

CLAassistant commented Aug 4, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@mangalaman93 mangalaman93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the test fail without your change?

db_test.go Outdated Show resolved Hide resolved
db_test.go Outdated Show resolved Hide resolved
db_test.go Outdated Show resolved Hide resolved
Signed-off-by: fatelei <fatelei@gmail.com>
@mangalaman93
Copy link
Contributor

Without this change, the test fails with the following segfault:

=== RUN   TestCloseDBWhileReading
badger 2023/08/04 14:25:22 INFO: All 0 tables opened in 0s
badger 2023/08/04 14:25:22 INFO: Discard stats nextEmptySlot: 0
badger 2023/08/04 14:25:22 INFO: Set nextTxnTs to 0
badger 2023/08/04 14:25:23 INFO: Lifetime L0 stalled for: 0s
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x8a7e71]

goroutine 44 [running]:
github.com/dgraph-io/badger/v4.(*memTable).IncrRef(...)
	/home/aman/gocode/src/github.com/dgraph-io/badger/memtable.go:230
github.com/dgraph-io/badger/v4.(*DB).getMemTables(0xc000660000)
	/home/aman/gocode/src/github.com/dgraph-io/badger/db.go:729 +0x131
github.com/dgraph-io/badger/v4.(*DB).get(0xc000660000, {0xc00a0971e0, 0xb, 0xb})
	/home/aman/gocode/src/github.com/dgraph-io/badger/db.go:763 +0x9d
github.com/dgraph-io/badger/v4.(*Txn).Get(0xc00a0a5900, {0xc000194120, 0x3, 0x3})
	/home/aman/gocode/src/github.com/dgraph-io/badger/txn.go:479 +0x2b5
github.com/dgraph-io/badger/v4.TestCloseDBWhileReading.func2.1(0xc000660000?)
	/home/aman/gocode/src/github.com/dgraph-io/badger/db_test.go:2657 +0x25
github.com/dgraph-io/badger/v4.(*DB).View(0x0?, 0xc0004d1fa8)
	/home/aman/gocode/src/github.com/dgraph-io/badger/txn.go:807 +0x9c
github.com/dgraph-io/badger/v4.TestCloseDBWhileReading.func2()
	/home/aman/gocode/src/github.com/dgraph-io/badger/db_test.go:2656 +0xf3
created by github.com/dgraph-io/badger/v4.TestCloseDBWhileReading
	/home/aman/gocode/src/github.com/dgraph-io/badger/db_test.go:2653 +0x185
exit status 2
FAIL	github.com/dgraph-io/badger/v4	1.033s

@mangalaman93 mangalaman93 merged commit cc2e2e7 into dgraph-io:main Aug 4, 2023
6 checks passed
@mangalaman93
Copy link
Contributor

Thanks for the PR @fatelei, appreciate you spending time on it.

@fatelei
Copy link
Contributor Author

fatelei commented Aug 4, 2023

Thanks for the PR @fatelei, appreciate you spending time on it.

you are welcome

@solracsf
Copy link

solracsf commented Aug 4, 2023

Will this (or any other fix) be backported to v3?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: Panic when closing DB while other goroutines doing reads
5 participants