Skip to content

TransactionSynchronizationUtils.unwrapResourceIfNecessary() does not unwrap OSGi service proxies [SPR-7368] #12026

@spring-projects-issues

Description

@spring-projects-issues

Ric Klaren opened SPR-7368 and commented

We experienced deadlocks in our product while load testing. The issue occurs when mixing Hibernate Sessions with JdbcTemplate code. What basically happens:

  1. The session in view filter creates a new Hibernate Session.
  2. The HibernateTransactionManager registers a JDBC datasource in the thread local map using the real class.
  3. Somewhere in a service call (and transaction) the user details are requested via the JdbcUserDetailsManager (from spring security) which is implemented as a JdbcTemplate. The JdbcTemplate has a JDK proxy of the datasource. This leads to a lookup in the thread local map with the proxy in stead of the real data source. Since TransactionSynchronizationUtils.unwrapResourceIfNecessary() does not unwrap JDK proxies the lookup fails. As a result the existing connection is not reused and a new connection is requested from the connection pool.

This deadlocks when the connection pool has no connections left.

(Checked the code up to 3.0.3 Release in which this is also present)


Affects: 3.0 GA

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions