question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hello, I’m is using some spring libraries, that call queries via jdbcTemplate and transactionTemplate. I have encountered a problem. If exposed transactions are used with Spring transactionTemplate there is a connection leak.

Issue project: https://github.com/neetkee/exposed-jdbc-template-demo. You can just run tests to reproduce the problem. Error:

Could not open JDBC Connection for transaction; nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30005ms.
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30005ms.
	at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:309)
	at org.jetbrains.exposed.spring.SpringTransactionManager.doBegin(SpringTransactionManager.kt:41)
	at org.springframework.transaction.support.AbstractPlatformTransactionManager.startTransaction(AbstractPlatformTransactionManager.java:400)
	at
Omitted

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Tapaccommented, Jun 4, 2021

@neetkee , thank you very much for providing such a complex sample. Looks like I was able to debug and fix that tricky case. I copy-pasted your test-sample into Exposed project. I will try to release the fix by the end of the week

0reactions
AleksanderBrzozowskicommented, May 24, 2021

We had the same issue in our project, everything worked for a small load, but when we did performance tests, connection leaks started to occur.

We have created something like this to fix this:

// this class is exposed as a bean
class TransactionOperations(datasource: Datasource) {
    private val db = Database.connect(datasource)
    
    operator fun <T> invoke(block: () -> T): T {
        //exposed transaction
        return transaction(..., db = db) { callback() }
    }
}

Since you don’t use @Transactional annotation, you could try it to 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Detecting and Resolving Database Connection Leaks with ...
Take a look at this tutorial that demonstrates how you can find and remove connection leaks between your application and database in Java...
Read more >
Connection Leak - Metawerx Java Wiki
A situation which occurs when a connection is opened, then forgotten about. This is known as a "leak", because each time it happens,...
Read more >
How to solve database connection leaks? - IBM
The database connection leaks should be identified and fixed in the code. It can be accomplished by using the dbconnection watchdog logger.
Read more >
Find Connection leak in Java application - Stack Overflow
If you need to find out leaks you can use profilers like yourkit or jprofiler which is able to track socket/jdbc leaks.
Read more >
The best way to detect database connection leaks
A connection leak happens when a connection is acquired without ever being closed. When should connection leaks be detected? Every relational ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found