Skip to content

Commit bbdf29e

Browse files
committed
Bump commons-pool2 to 2.13.1
Since 2.13.0, GenericObjectPool.invalidateObject always tries to add a replacement object to the pool (POOL-424). In 2.3 it created one only when a thread was waiting to borrow. A File Writer that does not keep connections open destroys its connection with invalidateObject after every message, so on 2.13 it would open another FTP, SFTP, SMB, WebDAV or S3 connection that nothing uses, until the evictor closes it. If opening that connection failed, invalidateObject threw before FileConnector dropped the destroyed connection from its open connections, so a later disconnect() reached it again. When a File Writer does not keep connections open, its pool now has maxIdle 0, and destroyConnection returns the connection instead of invalidating it. returnObject destroys a connection the pool has no idle capacity for, and creates a replacement only for a waiting thread, which is what invalidateObject did in 2.3. maxIdle 0 with invalidateObject alone would leave waiting threads blocked, because addObject respects maxIdle since 2.13.0 (POOL-425). Connections are not validated on return in this mode, since they are destroyed anyway; validation on borrow is unchanged. File Readers and writers that keep connections open still use invalidateObject. The open connection is now dropped in a finally block, so a failure in the pool can't leave it behind. Use the Duration setters for the eviction settings, since 2.13.1 deprecates setTimeBetweenEvictionRunsMillis and setMinEvictableIdleTimeMillis. A zero interval still disables the evictor. The verification metadata drops commons-pool2 2.3 and its parent POM, commons-parent 34, which nothing else uses, and the unused 2.13.0 entry. The 2.13.1 parent, commons-parent 93, is already listed. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Tony Germano <tony@germano.name>
1 parent 561c475 commit bbdf29e

3 files changed

Lines changed: 42 additions & 39 deletions

File tree

‎gradle/libs.versions.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ commons-lang3 = { module = "org.apache.commons:commons-lang3", version = "3.20.0
105105
commons-logging = { module = "commons-logging:commons-logging", version = "1.3.5" }
106106
commons-math3 = { module = "org.apache.commons:commons-math3", version = "3.0" }
107107
commons-net = { module = "commons-net:commons-net", version = "3.9.0" }
108-
commons-pool2 = { module = "org.apache.commons:commons-pool2", version = "2.3" }
108+
commons-pool2 = { module = "org.apache.commons:commons-pool2", version = "2.13.1" }
109109
commons-text = { module = "org.apache.commons:commons-text", version = "1.15.0" }
110110
commons-vfs2 = { module = "org.apache.commons:commons-vfs2", version = "2.10.0" }
111111
derby = { module = "org.apache.derby:derby", version.ref = "derby" }

‎gradle/verification-metadata.xml‎

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,11 +1481,6 @@
14811481
<sha256 value="53d0011352e2e5106f379dafccdac7754ec6f0f78243c0305e4969f5acddf8fb" origin="Generated by Gradle"/>
14821482
</artifact>
14831483
</component>
1484-
<component group="org.apache.commons" name="commons-parent" version="34">
1485-
<artifact name="commons-parent-34.pom">
1486-
<sha256 value="3a2e69d06d641d1f3b293126dc9e2e4ea6563bf8c36c87e0ab6fa4292d04b79c" origin="Generated by Gradle"/>
1487-
</artifact>
1488-
</component>
14891484
<component group="org.apache.commons" name="commons-parent" version="39">
14901485
<artifact name="commons-parent-39.pom">
14911486
<sha256 value="87cd27e1a02a5c3eb6d85059ce98696bb1b44c2b8b650f0567c86df60fa61da7" origin="Generated by Gradle"/>
@@ -1571,20 +1566,12 @@
15711566
<sha256 value="8a64e6b36a219886246b7851dfb808a2ce9b84248f3015396d7a2f92f6aa53e0" origin="Generated by Gradle"/>
15721567
</artifact>
15731568
</component>
1574-
<component group="org.apache.commons" name="commons-pool2" version="2.13.0">
1575-
<artifact name="commons-pool2-2.13.0.jar">
1576-
<sha256 value="488ededfcc481666845265a64dccc322fc8f0205940b4943a53de2d8ed04c48c" origin="Generated by Gradle"/>
1577-
</artifact>
1578-
<artifact name="commons-pool2-2.13.0.pom">
1579-
<sha256 value="4a961c2f7718508716618ad31fb41cb7a5cb749428ad0a19b8ff4d0d7f0b0934" origin="Generated by Gradle"/>
1580-
</artifact>
1581-
</component>
1582-
<component group="org.apache.commons" name="commons-pool2" version="2.3">
1583-
<artifact name="commons-pool2-2.3.jar">
1584-
<sha256 value="3e794e75be78f63cc31b6676697e45f07085903a1039169459132513d85c62ae" origin="Generated by Gradle"/>
1569+
<component group="org.apache.commons" name="commons-pool2" version="2.13.1">
1570+
<artifact name="commons-pool2-2.13.1.jar">
1571+
<sha256 value="f77a5060d6936a9144023584232f9de3f2248f1abfe156e9d31795f18770674f" origin="Generated by Gradle"/>
15851572
</artifact>
1586-
<artifact name="commons-pool2-2.3.pom">
1587-
<sha256 value="256b8598d469b7b20f92fd70406774d14b913b25affa02cd9488ddf6d1d3d55b" origin="Generated by Gradle"/>
1573+
<artifact name="commons-pool2-2.13.1.pom">
1574+
<sha256 value="89de9c86af44f8163f6a826eb71b80c93e90479de8b8d9229bc243e5a48e5e03" origin="Generated by Gradle"/>
15881575
</artifact>
15891576
</component>
15901577
<component group="org.apache.commons" name="commons-text" version="1.15.0">

‎server/src/main/java/com/mirth/connect/connectors/file/FileConnector.java‎

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
/*
2-
* Copyright (c) Mirth Corporation. All rights reserved.
3-
*
4-
* http://www.mirthcorp.com
5-
*
6-
* The software in this package is published under the terms of the MPL license a copy of which has
7-
* been included with this distribution in the LICENSE.txt file.
8-
*/
1+
// SPDX-License-Identifier: MPL-2.0
2+
// SPDX-FileCopyrightText: Mirth Corporation
3+
// SPDX-FileCopyrightText: 2026 Tony Germano
94

105
package com.mirth.connect.connectors.file;
116

127
import java.io.FileOutputStream;
138
import java.io.IOException;
149
import java.net.URI;
1510
import java.net.URISyntaxException;
11+
import java.time.Duration;
1612
import java.util.HashMap;
1713
import java.util.HashSet;
1814
import java.util.Iterator;
@@ -48,6 +44,7 @@ public class FileConnector {
4844
private boolean validateConnection;
4945
private int maxTotalConnections = GenericObjectPoolConfig.DEFAULT_MAX_TOTAL;
5046
private boolean keepConnectionOpen = false;
47+
private boolean closeConnectionsAfterUse = false;
5148
private String maxIdleTime;
5249

5350
public FileConnector(String channelId, ConnectorProperties connectorProperties, Connector connector) {
@@ -69,6 +66,7 @@ public FileConnector(String channelId, ConnectorProperties connectorProperties,
6966
this.validateConnection = fileDispatcherProperties.isValidateConnection();
7067
this.keepConnectionOpen = fileDispatcherProperties.isKeepConnectionOpen();
7168
this.maxIdleTime = fileDispatcherProperties.getMaxIdleTime();
69+
this.closeConnectionsAfterUse = !keepConnectionOpen;
7270
}
7371

7472
if (connector instanceof DestinationConnector) {
@@ -242,11 +240,23 @@ protected void disconnect() {
242240
*/
243241
protected void destroyConnection(FileSystemConnection connection, FileSystemConnectionOptions fileSystemOptions) throws Exception {
244242
if (connection != null) {
245-
ObjectPool<FileSystemConnection> pool = getConnectionPool(fileSystemOptions);
246-
pool.invalidateObject(connection);
247-
248-
synchronized (connections) {
249-
connections.remove(connection);
243+
try {
244+
ObjectPool<FileSystemConnection> pool = getConnectionPool(fileSystemOptions);
245+
if (closeConnectionsAfterUse) {
246+
/*
247+
* The pool keeps no idle connections in this mode, so returnObject destroys the
248+
* connection and creates a replacement only for a thread waiting to borrow.
249+
* invalidateObject would create none here, since addObject respects maxIdle, and
250+
* a waiting thread could block forever.
251+
*/
252+
pool.returnObject(connection);
253+
} else {
254+
pool.invalidateObject(connection);
255+
}
256+
} finally {
257+
synchronized (connections) {
258+
connections.remove(connection);
259+
}
250260
}
251261
}
252262
}
@@ -267,28 +277,34 @@ private synchronized ObjectPool<FileSystemConnection> getConnectionPool(FileSyst
267277
ObjectPool<FileSystemConnection> pool = pools.get(key);
268278

269279
if (pool == null) {
270-
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
280+
GenericObjectPoolConfig<FileSystemConnection> config = new GenericObjectPoolConfig<FileSystemConnection>();
271281
config.setMaxTotal(maxTotalConnections);
272282
config.setMinIdle(0); // The makes the evictor thread run, if active, no matter how few objects are in the pool
273-
config.setTimeBetweenEvictionRunsMillis(1000); // How often the evictor thread checks for objects to evict
283+
config.setTimeBetweenEvictionRuns(Duration.ofSeconds(1)); // How often the evictor thread checks for objects to evict
274284

275285
if (keepConnectionOpen) {
276286
int connectionMaxIdleTime = NumberUtils.toInt(maxIdleTime);
277287

278288
if (connectionMaxIdleTime == 0) {
279-
// Disable the eviction thread. https://commons.apache.org/proper/commons-pool/apidocs/org/apache/commons/pool2/impl/BaseGenericObjectPool.html#setTimeBetweenEvictionRunsMillis-long-
280-
config.setTimeBetweenEvictionRunsMillis(0);
289+
// Disable the eviction thread. A non-positive interval means no evictor runs.
290+
config.setTimeBetweenEvictionRuns(Duration.ZERO);
281291
} else {
282-
config.setMinEvictableIdleTimeMillis(connectionMaxIdleTime);
292+
config.setMinEvictableIdleDuration(Duration.ofMillis(connectionMaxIdleTime));
283293
}
284294
} else {
285295
// Always evict objects on the next check by the evictor thread
286-
config.setMinEvictableIdleTimeMillis(1);
296+
config.setMinEvictableIdleDuration(Duration.ofMillis(1));
297+
}
298+
299+
if (closeConnectionsAfterUse) {
300+
// Never keep idle connections, so that destroyConnection can return them to be destroyed
301+
config.setMaxIdle(0);
287302
}
288303

289304
if (isValidateConnection()) {
290305
config.setTestOnBorrow(true);
291-
config.setTestOnReturn(true);
306+
// Returned connections are always destroyed when they are not kept open
307+
config.setTestOnReturn(!closeConnectionsAfterUse);
292308
}
293309
pool = new GenericObjectPool<FileSystemConnection>(fileSystemConnectionFactory, config);
294310

0 commit comments

Comments
 (0)