-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEATURE: Way to shutdown a connection pool #68
Comments
Hmm. Yeah, I can see how this would be useful. I just let the connections expire because they only have a 15 second timeout on them by default. I've tinkered with it a bit and the way the pool is written right now really doesn't lend itself to being shut down. Between its super async implementation and the lack of bookkeeping (it has no idea what connections are acquired) it's looking real tricky to figure out a way to shut it down. Best I've come up with so far is this: @Override
public synchronized void close() {
for (int i = 0; i < connectionLimit; i++) {
acquire().thenAccept(this::remove);
}
} which has the unfortunate effect of opening as many connections as needed up to the limit before closing them, if they don't already exist. |
How about using a concurrent hashset to track the open connections? |
So I am playing with using the DefaultConnectionManager with a wapper to manage the forward open without using the connection pool. I am finding that the DefaultConnectionManager does not properly close the connection.
This is my wrapper package io.tlf.cip.tool.cip;
import com.digitalpetri.enip.cip.CipClient;
import com.digitalpetri.enip.cip.CipConnectionPool;
import com.digitalpetri.enip.cip.epath.EPath;
import com.digitalpetri.enip.cip.structs.ForwardCloseResponse;
import java.util.concurrent.ExecutionException;
public class ConnectionForwarder {
private final CipConnectionPool.CipConnectionFactory connectionFactory;
public ConnectionForwarder(CipClient client, EPath.PaddedEPath connectionPath, int connectionSize) {
this(
new CipConnectionPool.DefaultConnectionFactory(client, connectionPath, connectionSize)
);
}
public ConnectionForwarder(
CipConnectionPool.CipConnectionFactory connectionFactory
) {
this.connectionFactory = connectionFactory;
}
public CipConnectionPool.CipConnection open() throws ExecutionException, InterruptedException {
return connectionFactory.open().get();
}
public ForwardCloseResponse close(CipConnectionPool.CipConnection connection) throws ExecutionException, InterruptedException {
return connectionFactory.close(connection).get();
}
} Here is my usage of it: ConnectionForwarder forwarder = new ConnectionForwarder(client, connectionPath, connectionSize);
CipConnectionPool.CipConnection connection = null;
try {
connection = forwarder.open();
recvBuff = client.invokeConnected(connection.getO2tConnectionId(), genericService).get();
} catch (Exception ex) {
var response = exceptionResponse(ex);
entry.setResponse(response);
entry.setException(ex);
return response;
} finally {
try {
if (connection != null) {
forwarder.close(connection);
}
} catch (Exception ex) {
System.err.println("Failure to close connection");
ex.printStackTrace();
}
} I'm not sure exactly what is causing the failure in closing the connection. It is almost like the close message sent had an invalid connection ID (I have not verified this) The actual message sent via the forward open using the I was not getting this close error with the connection pool, but I am not sure that it was actually trying to close the connection, I was definitely exhausting the connections on the ethernet card with it as well. Thoughts? Thanks for the help, |
Hmm, this error does mean the connection is not found...
I'll have to see if I get the same error with one of our devices. The "triad" should be the connection serial number, originator vendor id, and originator serial number. |
Thanks for looking into it. |
OK, I can confirm that I do not have the issue when testing with the 1756-ENET, this may be an issue with the EWEB module. |
Hello,
Can you please provide a way to shutdown a connection pool that will close all connections and empty the pool?
I am running into an issue that the pool is leaving hanging connections once I am done using it, with no way to clean up the connections prior to it getting GC'd.
Thanks,
Trevor
The text was updated successfully, but these errors were encountered: