[ 
https://issues.apache.org/jira/browse/TOMEE-4731?focusedWorklogId=1049229&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1049229
 ]

ASF GitHub Bot logged work on TOMEE-4731:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 22/Oct/26 07:58
            Start Date: 22/Oct/26 07:58
    Worklog Time Spent: 10m 
      Work Description: rzo1 opened a new pull request, #3122:
URL: https://github.com/apache/tomee/pull/3122

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




Issue Time Tracking
-------------------

    Worklog Id:     (was: 1049229)
    Time Spent: 20m  (was: 10m)

> TxThreadContextRestorer fails with NPE when managed threads end after the 
> container shut down
> ---------------------------------------------------------------------------------------------
>
>                 Key: TOMEE-4731
>                 URL: https://issues.apache.org/jira/browse/TOMEE-4731
>             Project: TomEE
>          Issue Type: Bug
>          Components: TomEE Core Server
>    Affects Versions: 10.2.0
>            Reporter: Richard Zowalla
>            Assignee: Richard Zowalla
>            Priority: Major
>             Fix For: 11.0.0, 10.3.0
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to