dev@grizzly.java.net

About connection leak

From: Bongjae Chang <bongjae.chang_at_gmail.com>
Date: Thu, 29 Mar 2012 18:53:10 +0900

Hi,

When I used grizzly-memcached, I experienced connection leak when the trial
of connecting a server was timed out.

Connecting logic is simple.
---
final Future<Connection> future = connectorHandler.connect(serverAddr);
final Connection<SocketAddress> connection;
try {
   connection = future.get(shortTimeout, timeunit);
} catch( ...) {
   ...
} catch(TimeoutException te) {
   // at this point, connection is null and I don't need to get a connection
anymore. ---(1)
} 
---
When it was timed out at (1), the connection is null. So I couldn't
disconnect the connection.
At (1), the only way which I could try to do was "future.cancel()" but the
connection was not disconnected. If the connection will be established
successfully after timeout, the connection will be alive forever.
I would like to know how to disconnect the late connection after timeout in
order to prevent the connection leak.
Thanks.
Regards,
Bongjae Chang