Bug in state handling in Txn.
See original GitHub issueEncountered a potential bug with how a failed txn.commit
is handled.
Results in:
Unexpected exception, expected<org.lmdbjava.Env$MapFullException> but was<org.lmdbjava.Txn$NotReadyException>
it boils down to (TXN:107
):
state = DONE;
checkRc(LIB.mdb_txn_commit(ptr));
first setting the state to DONE
and then committing a txn
which can throw e.g. MapFullException
.
Shouldn’t the lines be switched?
Or is the try ... catch
pattern misused here?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Bug #1798485 “txn-queue for $ID is “machines” has too many ...
1) The machine document has 1000 transactions in its queue, which historically has been a sign that some transaction has gone wrong, and...
Read more >What the 'Bitcoin Bug' Means: A Guide to Transaction ...
It's an attack that lets someone change the unique ID of a bitcoin transaction before it is confirmed on the bitcoin network.
Read more >Full Text Bug Listing - Red Hat Bugzilla
Summary: Thin-arbiter: Have the state of volume in memory and use it for shd ... All further write txn failures are handled based...
Read more >Re: Weird behavior in transaction handling (Possible bug ?)
to track transaction state internally -- seems a bit ugly and unreliable. 7.4 returns COMMIT for rolled-back COMMITs, but does report ...
Read more >KIP-664: Provide tooling to detect and abort hanging ...
In KAFKA-9144, we encountered a bug which could lead to a transaction being left in a hanging state. When this happens, the last...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve had a good look at this issue today and I am of the view the current handling is correct.
I was able to run your test case and reproduce the failure. However the code is calling
Txn.commit()
, catching the raisedMapFullException
, and then unnecessarily invokingTxn.abort()
on what is by then an invalid transaction. TheMapFullException
was raised when you calledTxn.commit()
. The subsequent invocation ofTxn.abort()
raisesNotReadyException
because the transaction is no longer valid and the more meaningful exception had already been returned to user code earlier.By way of background, the LMDB C
mdb_txn_commit
documentation states, “The transaction handle is freed”. So this happens irrespective of the return code frommdb_txn_commit
. If one attempts to then callmdb_txn_abort
for the same transaction handle, the C library will crash. To illustrate inverting theTxn.java:107
statement your test case crashes the JVM with “The forked VM terminated without properly saying goodbye. VM crash or System.exit called?”.LmdbJava protects you from a segmentation fault by raising the
NotReadyException
when an attempt is made to use a transaction that can no longer be aborted (as in this case). The correct method to call (and what will be called ifTxn
was created in the initialization of a try-with-resources block) isTxn.close()
. TheTxn.close()
method will not raise any LMDB-related exception.I hope this clarifies things. In a nutshell, don’t commit then abort. Just commit or abort, then close.
Thanks for the clarification.