-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Endless loop with DataSourceUtils in spring-jdbc #34484
Comments
Are you claiming that this is a regression that did not occur before Spring Framework 6.2.2? In any case, can you please provide a small sample application that reproduces the problem (preferably something that we can download and run, such as a public Git repository or a ZIP file attached to this issue)? Thanks |
Sorry, I didn't make that clear. It occurs both in 6.2.2 and 6.2.3, I have not tested other versions. |
Hi Sam, I managed to distill the issue into a mini-project here: Upon executing Main.main you will first enter the Please let me know, if you need further help or info. As I said, as I do not understand the concepts within the spring code, I am not sure, what the best way to solve this is. My assumption would be, |
I was able to reproduce this locally but only with the very specific configuration in your repro project. Changing |
It's caused by the Hibernate connection release mode which our |
Aside from the Hibernate connection release mode, it is also unusual to provide a In any case, I've revised this for more defensiveness in |
Thanks a lot for the quick fix. |
DataSourceUtils resolution
getTargetConnection
gets stuck in an endless loop under certain conditions in spring-jdbc 6.2.2/6.2.3.I am creating a
DataSource
, wrapping it into theTransactionAwareDataSourceProxy
and then creating anEntityManagerFactory
. Then the datasource and the emf both get posted to aJpaTransactionManager
.Upon trying to commit a transaction, the application goes into an endless loop in
DataSourceUtils.getTargetConnection()
.As far as I could understand it by debugging, the following happens.
TransactionAwareDataSourceProxy
gets asked for a connection and creates a lazy initialization proxy. As this proxy is lazy, it does not initialize an inner. The proxy handler is theTransactionAwareInvocationHandler
.Next step is, that this proxy gets bound to the current transaction-context in the
TransactionSynchronizationManager
. This happens duringJpaTransactionManager.doBegin(Object, TransactionDefinition)
.Now, during release of the connection while committing, the connection proxy gets into
DataSourceUtils.getTargetConnection()
and there it is determined, it is an instanceofConnectionProxy
and therefore gets resolved withinTransactionAwareDataSourceProxy
, which delegates toDataSourceUtils.doGetConnection
, which delegates toTransactionSynchronizationManager.getResource
which returns the uninitialized proxy.I am not quite sure, why most invocations do not trigger this issue and some do. My current assumption is, that there is no issue, as long as the databaseconnection is actually used within the transaction. We have, however, cases, where a spring bean caches data, requests a transaction but does not actually trigger database queries upon cache-hits.
I am not quite sure, how to solve this correctly. Probably a non-initialized proxy for a connection should not be registered at all within the
TransactionAwareDataSourceProxy
?The text was updated successfully, but these errors were encountered: