Skip to content

Database connection problems cause Spring to raise an IllegalStateException and resulting in transaction state not being cleaned up [SPR-5133] #9806

@spring-projects-issues

Description

@spring-projects-issues

Matt Doran opened SPR-5133 and commented

We have customers encounter a strange "Pre-bound JDBC Connection found!", even though we only ever use the HibernateTransactionManager, and never any JDBC transaction manager. This error has happened with a number of our customers, but we have been unable to reproduce it in house.

From some client logs, I noticed that this error only started appearing after the backend database was down for a period. So there were lots of errors indicating that transactions could not be started. After the database came online the "Pre-bound JDBC Connection found!" started occurring.

The background on this issue can be found at the following forum thread (I was receiving help from Martin Deinum, and he asked me to raise the issue here).

http://forum.springframework.org/showthread.php?t=59316

So I decided to try to reproduce the problem by deliberately bringing down the database connection, and trying to perform transactions. Although I was unable to produce the identical behaviour, I could reproduce a situation that would cause Spring to throw an IllegalStateException in the "TransactionSynchronizationManager.clearSynchronization()" method. This method is called from AbstractPlatformTransactionManager.cleanupAfterCompletion(). When this exception is raised the remainder if this method will not run, so the transaction cleanup method "doCleanupAfterCompletion" will not be called and the suspended resources would not be resumed.

So it's possible that these connection errors cause the transaction state from a previous transaction to be left behind ... and when Spring finds the pre-bound connection from the previous transaction it raises the above error. It's only a theory, but it sounds plausible.

I have been able to create a simple reproduction recipe. It shows that instead of getting an exception explaining that a connection cannot be established, you get a "java.lang.IllegalStateException: Cannot deactivate transaction synchronization - not active" instead. I will attach the reproduction after creating the issue. It is in the form of an Eclipse project ...all you need to do is run the "springdbrepro.Main" class. You do not need to setup any databases, etc.

NOTE: I have tried this in 2.0.8 and it does not produce the IllegalStateException. I did not test this in 2.5, because our code is using Hibernate 3.0.5 which is not supported in the later versions of Spring. I might upgrade to 2.0.8 ... but I thought it would be worth raising this issue ... because this problem could be lurking in future versions too.


Affects: 1.2.9

Attachments:

Issue Links:

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