You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While I was testing the stability of a modbus application based on plc4x, I faced the problem that on successful reconnection attempts the number of live threads keeps increasing continuously. Specifically, there is a pool as such: pool-N-thread-M (probably related to netty) which sits waiting and does not shut down.
The same applies when using the CachedPlcConnectionManager
Connection string: modbus-tcp://127.0.0.1:9081?unit-identifier=1
Here is a sample code with springboot:
@Scheduled(fixedDelayString = "${scheduling.interval}")
publicvoidupdate() {
logger.info("Executing update method...")
try {
reconnect(false);
if (plcConnection == null || !plcConnection.isConnected()) {
logger.info("PLC connection is not alive, exiting...");
return;
}
logger.info("OK");
} catch (Exceptione) {
logger.error("Error while trying to read ... reconnecting", e);
}
}
protectedvoidreconnect(booleanerror) {
try {
try {
if (plcConnection != null && !plcConnection.isConnected()) {
logger.info("Reconnecting...");
// either with plcConnection.connect() or// connectionManager.getConnection(plcConnectionString); There is a n increment// of threads// plcConnection = connectionManager.getConnection(plcConnectionString);plcConnection.connect();
return;
}
} catch (Exceptione) {
logger.error("Error: {}", e.getMessage());
return;
}
// Open a new oneif (plcConnection == null) {
logger.info("Connecting...");
plcConnection = connectionManager.getConnection(plcConnectionString);
}
} catch (Exceptionex) {
logger.error("Error while trying to reconnect to the plc");
}
}
The function runs with a 10 seconds interval, in this time window I simulate the disconnection/reconnection of the cable.
I'm attaching a small video which shows this behavior more clearly.
I understand that this is a corner case but it can lead to a waste of resources which I would like to avoid.
What happened?
While I was testing the stability of a modbus application based on plc4x, I faced the problem that on successful reconnection attempts the number of live threads keeps increasing continuously. Specifically, there is a pool as such: pool-N-thread-M (probably related to netty) which sits waiting and does not shut down.
The same applies when using the CachedPlcConnectionManager
Connection string: modbus-tcp://127.0.0.1:9081?unit-identifier=1
Here is a sample code with springboot:
The function runs with a 10 seconds interval, in this time window I simulate the disconnection/reconnection of the cable.
I'm attaching a small video which shows this behavior more clearly.
I understand that this is a corner case but it can lead to a waste of resources which I would like to avoid.
Screencast.2025-08-27.13.38.08.mp4
Thank you.
Version
v0.13.0
Programming Languages
Protocols