question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug in state handling in Txn.

See original GitHub issue

Encountered a potential bug with how a failed txn.commit is handled.

Test case: https://github.com/dzajkowski/lmdbjava/blob/e0d6b6c545970847f6288d84421a919150278397/src/test/java/org/lmdbjava/TxnTest.java#L265

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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
benalexaucommented, Dec 8, 2018

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 raised MapFullException, and then unnecessarily invoking Txn.abort() on what is by then an invalid transaction. The MapFullException was raised when you called Txn.commit(). The subsequent invocation of Txn.abort() raises NotReadyException 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 from mdb_txn_commit. If one attempts to then call mdb_txn_abort for the same transaction handle, the C library will crash. To illustrate inverting the Txn.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 if Txn was created in the initialization of a try-with-resources block) is Txn.close(). The Txn.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.

0reactions
dzajkowskicommented, Dec 8, 2018

Thanks for the clarification.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found