rzo1 opened a new pull request, #3121: URL: https://github.com/apache/tomee/pull/3121
https://issues.apache.org/jira/browse/TOMEE-4731 Threads created by `ManagedThreadFactoryImpl` (e.g. the workers of the default `ManagedExecutorService`) run their whole life inside the default context service, which clears the transaction context. The restorer created on entering that context always called `OpenEJB.getTransactionManager().resume(..)` on exit, even if `suspend()` had returned `null`. When such a thread terminates after the container has been shut down, the `TransactionManager` is gone and every pool thread dies with: ``` java.lang.NullPointerException: Cannot invoke "jakarta.transaction.TransactionManager.resume(jakarta.transaction.Transaction)" because the return value of "org.apache.openejb.OpenEJB.getTransactionManager()" is null at org.apache.openejb.threads.impl.TxThreadContextProvider$TxThreadContextRestorer.endContext(TxThreadContextProvider.java:79) ``` ### Changes - `TxThreadContextClearingSnapshot.begin()` returns the no-op restorer if no transaction was suspended. - `TxThreadContextRestorer.endContext()` skips `resume` (logging a warning) if a suspended transaction cannot be resumed because the `TransactionManager` is no longer available. - Behaviour while the container is running is unchanged: a suspended transaction is still resumed. ### Tests `TxThreadContextProviderTest`: no-op restorer without a transaction, a suspended transaction is resumed, no failure once the `TransactionManager` is 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. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
