Skip to content

Commit 6eb6e4a

Browse files
author
Georgi Neykov
committed
fix(client): Close connections immediately with connection pooling disabled.
- Update `ConnectionPool` to directly close a `RealConnection` submitted to `ConnectionPool.recycle()` if the pool is instantiated with the `maxIdleConnections` parameter set to 0 (no pooling) for whatever reason.
1 parent 41066fc commit 6eb6e4a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

binapi-client/src/main/java/com/pcloud/networking/client/ConnectionPool.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,17 @@ synchronized RealConnection get(Endpoint endpoint) {
139139
}
140140

141141
synchronized void recycle(RealConnection connection) {
142-
if (!cleanupRunning) {
143-
cleanupRunning = true;
144-
CLEANUP_THREAD_EXECUTOR.execute(cleanupRunnable);
142+
if (maxIdleConnections > 0) {
143+
if (!cleanupRunning) {
144+
cleanupRunning = true;
145+
Connections.CLEANUP_THREAD_EXECUTOR.execute(cleanupRunnable);
146+
}
147+
connection.setIdle(System.nanoTime());
148+
connections.add(connection);
149+
} else {
150+
// No idle connections allowed, close immediately.
151+
connection.close(false);
145152
}
146-
connection.setIdle(System.nanoTime());
147-
connections.add(connection);
148153
}
149154

150155
/**

0 commit comments

Comments
 (0)