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.

Rider is leaking connections when cacheConnections = false

See original GitHub issue

DBUnitExtension is leaking connections when the cacheConnections flag is false. If the are more than X tests and the connection pool has X connections the subsequent tests fails when waiting for checking out new connections. The if the flag is set DataSetExecutorImpl.instance method doesn’t set the connectionHolder to the context which means that the beforeTestExecution must close the connection, which it doesn’t.

        if (instance == null) {
            instance = new DataSetExecutorImpl(executorId, connectionHolder,
                    DBUnitConfig.fromGlobalConfig().executorId(executorId));
            log.debug("creating executor instance " + executorId);
            executors.put(executorId, instance);
        } else if (!instance.dbUnitConfig.isCacheConnection()) {
            instance.setConnectionHolder(connectionHolder);
        }

Also, even the cached connection seems to be never closed.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
hhegcommented, Jul 14, 2021

Hi @rmpestano. I think your exception is different from mine. My tests fails explicitly with a timeout exception when trying to checkout a connection, they all timeout after 30 seconds which is the timeout limit for Hikari connection checkout. I don’t think DBRider should manage any connection at all but return them when they are done with it. This to let the container run un-interfered since this will not happen in production. That’s why we were running with the connectionCached = false set.

1reaction
rmpestanocommented, Jul 14, 2021

Hi @hheg, I’ve added a test on junit5 module and indeed when cacheConnection=false it is failing after the first test is run. The second test will fail to retrieve information from the connection (probably because it is closed):


java.lang.RuntimeException: Could not get driver information from provided connection.

	at com.github.database.rider.core.util.DriverUtils.getDriverName(DriverUtils.java:50)
	at com.github.database.rider.core.connection.RiderDataSource.init(RiderDataSource.java:75)
	at com.github.database.rider.core.connection.RiderDataSource.<init>(RiderDataSource.java:48)
	at com.github.database.rider.core.dataset.DataSetExecutorImpl.getRiderDataSource(DataSetExecutorImpl.java:1023)
	at com.github.database.rider.core.RiderRunner.setup(RiderRunner.java:31)
	at com.github.database.rider.junit5.DBUnitExtension.beforeTestExecution(DBUnitExtension.java:60)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeTestExecutionCallbacks$4(TestMethodTestDescriptor.java:184)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeMethodsOrCallbacksUntilExceptionOccurs$5(TestMethodTestDescriptor.java:195)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeMethodsOrCallbacksUntilExceptionOccurs(TestMethodTestDescriptor.java:195)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeTestExecutionCallbacks(TestMethodTestDescriptor.java:183)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:129)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:65)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
	Suppressed: java.lang.RuntimeException: Could not get driver information from provided connection.
		at com.github.database.rider.core.util.DriverUtils.getDriverName(DriverUtils.java:50)
		at com.github.database.rider.core.connection.RiderDataSource.init(RiderDataSource.java:75)
		at com.github.database.rider.core.connection.RiderDataSource.<init>(RiderDataSource.java:48)
		at com.github.database.rider.core.dataset.DataSetExecutorImpl.getRiderDataSource(DataSetExecutorImpl.java:1023)
		at com.github.database.rider.core.RiderRunner.teardown(RiderRunner.java:109)
		at com.github.database.rider.junit5.DBUnitExtension.afterTestExecution(DBUnitExtension.java:84)
		at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeAfterTestExecutionCallbacks$8(TestMethodTestDescriptor.java:229)
		at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeAllAfterMethodsOrCallbacks$12(TestMethodTestDescriptor.java:269)
		at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
		at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeAllAfterMethodsOrCallbacks$13(TestMethodTestDescriptor.java:269)
		at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
		at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeAllAfterMethodsOrCallbacks(TestMethodTestDescriptor.java:268)
		at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeAfterTestExecutionCallbacks(TestMethodTestDescriptor.java:228)
		at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:133)
		... 43 more
	Caused by: java.sql.SQLNonTransientConnectionException: connection exception: connection does not exist
		at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
		at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
		at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
		at org.hsqldb.jdbc.JDBCUtil.connectionClosedException(Unknown Source)
		at org.hsqldb.jdbc.JDBCConnection.checkClosed(Unknown Source)
		at org.hsqldb.jdbc.JDBCConnection.getMetaData(Unknown Source)
		at com.github.database.rider.core.util.DriverUtils.getDriverName(DriverUtils.java:48)
		... 56 more
	Caused by: org.hsqldb.HsqlException: connection exception: connection does not exist
		at org.hsqldb.error.Error.error(Unknown Source)
		at org.hsqldb.error.Error.error(Unknown Source)
		... 61 more
Caused by: java.sql.SQLNonTransientConnectionException: connection exception: connection does not exist
	at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
	at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
	at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
	at org.hsqldb.jdbc.JDBCUtil.connectionClosedException(Unknown Source)
	at org.hsqldb.jdbc.JDBCConnection.checkClosed(Unknown Source)
	at org.hsqldb.jdbc.JDBCConnection.getMetaData(Unknown Source)
	at com.github.database.rider.core.util.DriverUtils.getDriverName(DriverUtils.java:48)
	... 54 more
Caused by: org.hsqldb.HsqlException: connection exception: connection does not exist
	at org.hsqldb.error.Error.error(Unknown Source)
	at org.hsqldb.error.Error.error(Unknown Source)
	... 59 more

Thanks for the heads up, I’ll investigate

Read more comments on GitHub >

github_iconTop Results From Across the Web

Database Rider Documentation - GitHub Pages
Database connection leak detection . ... Detecting connection leak . ... @DBUnit(cacheConnection = true, cacheTableNames = false, allowEmptyFields =.
Read more >
How to detect leaked datasource connections using the ...
How to detect leaked datasource connections using the cached connection manager (CCM) debug facility in JBoss EAP.
Read more >
Database Rider Versions - Open Source Agenda
Release notes · Rider is leaking connections when cacheConnections = false (#332) · Warning is issued if column value contains : (Colon) (#335)...
Read more >
DBUnit (rider-core 1.9.1 API) - Javadoc Extreme - Javadox
public abstract boolean cacheConnection ... Returns: if true will activate connection leak detection. Default: false ... Defaults to false. Default: false ...
Read more >
Connecting to the Caché Database
This example defines the CacheConnection object as a global that can be used ... Set Pooling to false to create a connection with...
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