-
Notifications
You must be signed in to change notification settings - Fork 1.1k
ConnectionPoolSupport provides no support for borrowObject with timeout #3623
Description
Bug Report
Current Behavior
borrowed pooled connections with timeout are not closed
I may be missing something, however it looks like ConnectionPoolSupport.createGenericObjectPool code may want a wrapper for the borrowObject(long timeout) method. Otherwise the borrowed objects require manual closing
Input Code
Please see a test case created in the 6.5.4.RELEASE version.
The test fails with the timeout after 10 seconds and getNumActive reports an increasing number of connections open
However if the borrowObject is called with no parameter (which should be equivalent to the timeout set to a very large number) the test works well and the getNumActive is 0 every time.
@Test
public void testPool() throws Exception {
GenericObjectPool<StatefulRedisConnection<String, String>> mypool = /* here the pool initialized for 256 connections max*/;
List<StatefulRedisConnection<String, String>> connections = new ArrayList<>();
int count = 300;
try {
for (int i = 0; i < count; i++) {
try (final StatefulRedisConnection<String, String> con = mypool.borrowObject(10_000)){
System.out.println("created %s connections".formatted( i + 1) );
connections.add(con);
}
System.out.println("Active: "+mypool.getNumActive());
}
} finally {
connections.forEach(StatefulConnection::close);
}
}Expected behavior/code
Connection is closed even if borrowed with the timeout
Environment
- Lettuce version(s): 6.5.4.RELEASE
- Redis version: 5+
Possible Solution
wrap borrowObject with timeout
Additional context
I did not test it on the newer versions, I just lookup the code and noticed no changes in the borrow mechanism.