NullPointerException in com.sun.jts.CosTransactions.RecoveryManager when restoring EJB timers

Hi,

we came across this issue with Payara 5.2020.4 and I just wanted to check if my understanding is correct.
One of our instances threw the following exception during startup:

[2021-09-09 06:03:54,145] [INFO ] [javax.enterprise.system.container.ejb.com.sun.ejb.containers] [Thread-21] [#1] ejb.timer_service_started [2021-09-09 06:03:54,145] [INFO ] [javax.enterprise.system.container.ejb.com.sun.ejb.containers] [Thread-21] [#1] ==> Restoring Timers ...
[2021-09-09 06:03:54,280] [INFO ] [org.eclipse.persistence.session./file:/home/xxx/applications/ejb-timer-service-app/WEB-INF/classes/___EJB__Timer__App] [Thread-21] [#1] EclipseLink, version: Eclipse Persistence Services - 2.7.6.payara-p1
[2021-09-09 06:04:01,096] [WARN ] [javax.enterprise.system.core.transaction.com.sun.jts.CosTransactions] [Thread-21] [#1] jts.unexpected_error_in_begin java.lang.NullPointerException at com.sun.jts.CosTransactions.RecoveryManager.waitForResync(RecoveryManager.java:1465)
    at com.sun.jts.CosTransactions.TransactionFactoryImpl.localCreate(TransactionFactoryImpl.java:180)
    at com.sun.jts.CosTransactions.CurrentImpl.begin(CurrentImpl.java:428)
    at com.sun.jts.jta.TransactionManagerImpl.begin(TransactionManagerImpl.java:296)
    at com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate.beginJTS(JavaEETransactionManagerJTSDelegate.java:496)
    at com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate.startJTSTx(JavaEETransactionManagerJTSDelegate.java:397)
    at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.startJTSTx(JavaEETransactionManagerSimplified.java:491)
    at com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate.enlistLAOResource(JavaEETransactionManagerJTSDelegate.java:316)
    at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.enlistResource(JavaEETransactionManagerSimplified.java:414)
    at com.sun.enterprise.resource.rm.SystemResourceManagerImpl.enlistResource(SystemResourceManagerImpl.java:103)

If I am not mistaken, the underlying source code should be this:

The field which is checked for NULL is static volatile but AFAIK this does not prevent other threads from NULLing the field concurrently after it has been checked, for example here:

Is someone able to confirm this? This issue occurred only once up to now.

Many thanks in advance and best regards,

Chris.

Yes, you’re right Chris, and congratulations to being that lucky hitting that race condition :slight_smile:

The fix would be to assign resyncInProgress to local variable before checking, as the semaphore would synchronize interleaved post and wait calls properly.

1 Like

Hi Chris,

Can you create a Github issue for this so that we can address this problem in a future version? A PR for this is also appreciated.

Thanks.

1 Like

Thanks for your replies and sorry for not responding earlier. I was expecting to get an email for new posts but somehow I didn’t. (unrelated question: how can I enable mail notifications?)

I will open a github issue and maybe even a PR (as time permits).

Thanks again.

Created Bug Report: NullPointerException in com.sun.jts.CosTransactions.RecoveryManager · Issue #5491 · payara/Payara · GitHub