Repository navigation
Fix a leaked transaction and a hang when transactions begin on several threads - #85
Open
AntonOresten wants to merge 1 commit into
Open
AntonOresten wants to merge 1 commit into
AntonOresten wants to merge 1 commit into
Conversation
`Transaction` pushed onto `env.txns` unsynchronized, so two threads beginning transactions in one environment could make the `push!` throw `ConcurrencyViolationError`. The transaction had already begun and its finalizer was not yet attached, so nothing ended it: a read-only transaction lost its reader slot, and a write transaction kept LMDB's writer mutex, blocking every later write transaction in `mdb_txn_begin`. Guard the list with a lock, and attach the finalizer before registering the transaction. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GqhLuqgqY1TAufNyxboLQj
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Transaction(env; …)registers each new transaction inenv.txnswith an unsynchronizedpush!, aftermdb_txn_beginand before the finalizer is attached. When two threads begin transactions in one environment at the same time, thatpush!can throwConcurrencyViolationError("Vector can not be resized concurrently"). The transaction has already begun in LMDB by then, it has no finalizer yet, and thedo-block method'sabortis never reached because the throw is in the constructor it calls. Nothing ever ends that transaction:mdb_txn_beginforever, and since that is a plainccall, the first garbage collection another thread asks for waits on it as well: the process sits at 0% CPU.Reproducer
With 3.0.1 on Julia 1.13.3 (Linux, aarch64) this prints
within a second and then hangs, on 2, 4 and 12 threads. With this change it prints
done.Fix
Environmentgets a lock fortxns, held for thepush!in theTransactionconstructor and whileclose(env)takes the list.The lock is a
SpinLockbecausecloseis also the environment's finalizer, and a finalizer must not wait on a lock that switches tasks.Test
test/threads.jlbegins read-only and write transactions from four threads in a child process, so that it has threads however the suite is started (CI runs it on one). Without the fix it failed in 10 of 10 runs on Julia 1.13; with it, it takes about half a second. The suite passes locally on Julia 1.10 and 1.13.Where this was met
Through CompilerCaching's LMDB object cache: several tasks loading cached GPU kernels at once, each in a read-only transaction, while one refreshes access times in a write transaction. The process froze at 0% CPU.
Not addressed here
env.txnsgains aWeakRefper transaction and is emptied only byclose(env), so a long-lived environment's list grows with every transaction it has begun. This change leaves that as it is.🤖 Generated with Claude Code
https://claude.ai/code/session_01GqhLuqgqY1TAufNyxboLQj