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

mdbx: race conditions in MdbxKV.Close (#8409) #9244

Merged
merged 3 commits into from
Jan 17, 2024
Merged

mdbx: race conditions in MdbxKV.Close (#8409) #9244

merged 3 commits into from
Jan 17, 2024

Conversation

battlmonstr
Copy link
Contributor

In the previous code WaitGroup db.wg.Add(), Wait() and db.closed were not treated in sync. In particular, it was theoretically possible to first check closed, then set closed and Wait, and then call wg.Add() while waiting (leading to WaitGroup panic).
In theory it was also possible that db.env.BeginTxn() is called on a closed or nil db.env, because db.wg.Add() was called only after BeginTxn (db.wg.Wait() could already return).

WaitGroup is replaced with a Cond variable.
Now it is not possible to increase the active transactions count on a closed database. It is also not possible to call BeginTxn on a closed database.

In the previous code WaitGroup db.wg.Add(), Wait() and db.closed were not treated in sync.
In particular, it was theoretically possible to first check closed, then set closed and Wait, and then call wg.Add() while waiting
(leading to WaitGroup panic).
In theory it was also possible that db.env.BeginTxn() is called on a closed or nil db.env,
because db.wg.Add() was called only after BeginTxn (db.wg.Wait() could already return).

WaitGroup is replaced with a Cond variable.
Now it is not possible to increase the active transactions count on a closed database.
It is also not possible to call BeginTxn on a closed database.
@battlmonstr battlmonstr merged commit 1914b52 into devel Jan 17, 2024
7 checks passed
@battlmonstr battlmonstr deleted the pr/8409 branch January 17, 2024 14:28
battlmonstr added a commit that referenced this pull request Jan 17, 2024
In the previous code WaitGroup db.wg.Add(), Wait() and db.closed were
not treated in sync. In particular, it was theoretically possible to
first check closed, then set closed and Wait, and then call wg.Add()
while waiting (leading to WaitGroup panic).
In theory it was also possible that db.env.BeginTxn() is called on a
closed or nil db.env, because db.wg.Add() was called only after BeginTxn
(db.wg.Wait() could already return).

WaitGroup is replaced with a Cond variable.
Now it is not possible to increase the active transactions count on a
closed database. It is also not possible to call BeginTxn on a closed
database.
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