Repository navigation
[tomee-10.x] TOMEE-4731 - Do not resume a transaction when there is none or the TransactionManager is gone - #3122
Merged
Merged
Conversation
…ansactionManager is gone Threads created by ManagedThreadFactoryImpl run their whole life inside the default context service, which clears the transaction context. The restorer created when entering that context always called OpenEJB.getTransactionManager().resume(..) on exit, even if suspend() had returned null. When such a thread terminated after the container had been shut down the TransactionManager was gone and the thread died with a NullPointerException. The clearing snapshot now returns the no-op restorer if no transaction was suspended, and the restorer skips resume (logging a warning) if the TransactionManager is no longer available.
jungm
approved these changes
Oct 22, 2026
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.
https://issues.apache.org/jira/browse/TOMEE-4731 (backport of the fix on main to tomee-10.x)
Threads created by
ManagedThreadFactoryImpl(e.g. the workers of the defaultManagedExecutorService) run their whole life inside the default context service, which clears the transaction context. The restorer created on entering that context always calledOpenEJB.getTransactionManager().resume(..)on exit, even ifsuspend()had returnednull. When such a thread terminates after the container has been shut down, theTransactionManageris gone and every pool thread dies with:Changes
TxThreadContextClearingSnapshot.begin()returns the no-op restorer if no transaction was suspended.TxThreadContextRestorer.endContext()skipsresume(logging a warning) if a suspended transaction cannot be resumed because theTransactionManageris no longer available.Tests
TxThreadContextProviderTest: no-op restorer without a transaction, a suspended transaction is resumed, no failure once theTransactionManageris gone, and a regression test for a managed thread terminating after shutdown. Three of the four fail without the fix (two with exactly the NPE above); the fourth guards the existing resume behaviour.