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

fix the deadlock when closing db #164

Merged
merged 1 commit into from
Jul 1, 2024
Merged

Conversation

KANIOYH
Copy link
Contributor

@KANIOYH KANIOYH commented Jul 1, 2024

Problem

find in bench_test.go: BenchmarkGet
db.Close() hold db.mu and close flushChan.

db.mu.Lock()
defer db.mu.Unlock()
close(db.flushChan)
<-db.closeChan

At the same time, the listenMemtableFlush -> db.flushMemtable may trying hold db.mu to flush memtable.

...
// delete old memtable kept in memory
db.mu.Lock()
if table == db.activeMem {
...

listenMemtableFlush blocked, it cannot send msg to closeChan, and db.Close() blocked in <-db.closeChan.

Solve

close flushChan without db.mu.

close(db.flushChan)
<-db.closeChan
db.mu.Lock()
defer db.mu.Unlock()

@yanxiaoqi932 yanxiaoqi932 merged commit 3082d67 into lotusdblabs:main Jul 1, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants