-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug Report: DataSource.getConnection() blows up on transaction with wrong status/FISH-7451 #6274
Comments
After debugging I found the following. When getting the connection from the datasource in the ResourceManagerImpl at line 150 the current transaction is checked. This transaction is retrieved using ComponentInvocation.getTransaction().
If there is a transaction it will call enlistResource which at some point checks the transaction status and a COMMITTED tx throws an exception. I noticed that when the EntityListener2 is not there then the 'tran' variable is null and the transaction status is not checked and no exception is thrown. So why is the it null? I found that when using
then this interceptor class is used
when using
then this interceptor class is used
So I investigated those. This is what is happening: the TransactionalInterceptorRequiresNew will suspend the current transaction (if its there) and create a new one in which the code is executed. After executing the code the current transaction is suspended. But the thing is, this interceptor also registers the transaction on the ComponentInvocation. And when it suspends the transaction after running the actual code it not only suspends the transaction but it also registeres this transaction on the ComponentInvocation, even if there was none before the interceptor started. And this seems to be the problem. Before running EntityListener2 there is no tx on ComponentInvocation, but when its done there is. Ultimately this is then causing the exception described above. So it looks like a bug but I'm not sure. The TransactionManager interface has multiple implementations and I don't know if payara always uses the same implementation. Currently it is using the
and the resume method also calls preInvokeTx() which is setting the tx on ComponentInvocation.
A fix could be to 'remember' if there was a tx on the ComponentInvocation and if not set it to null after suspending the tx. |
Hi @thehpi , This has been escalated this to the platform development team as FISH-7451. Best Regards, |
The PR with fix was merged, thank you! |
Hi @thehpi, This issue has been fixed in Payara 6.2023.8 which will be available in the next release. Thank you, |
Brief Summary
When using two entity listeners where one is using @transactional(Transactional.TxType.REQUIRES_NEW) this causes problems when doing DataSource.getConnection() after observing an event using @observes(during = TransactionPhase.AFTER_SUCCESS).
See the reproducer: https://github.com/thehpi/payara-after-success
Expected Outcome
I expect to always be able to get a connection from a datasource, regardless of what other processing has been done before using entity listeners or observers.
Current Outcome
An exception is thrown:
Reproducer
https://github.com/thehpi/payara-after-success
Operating System
MacOSX Ventura 13.3.1
JDK Version
openjdk 11.0.17 2022-10-18
Payara Distribution
Payara Server Full Profile: 6.2023.2
The text was updated successfully, but these errors were encountered: