Skip to content

Commit

Permalink
IGNITE-20740 Fix SocketChannel leak when connection fails (#11016)
Browse files Browse the repository at this point in the history
Co-authored-by: Pavel Tupitsyn <[email protected]>
  • Loading branch information
shoothzj and ptupitsyn authored Oct 30, 2023
1 parent 63f1a80 commit eb57f7d
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,31 @@ public GridNioClientConnectionMultiplexer(ClientConfiguration cfg) {
rwLock.readLock().lock();

try {
SocketChannel ch = SocketChannel.open();
ch.socket().connect(new InetSocketAddress(addr.getHostName(), addr.getPort()), connTimeout);
SocketChannel ch = null;
try {
ch = SocketChannel.open();
ch.socket().connect(new InetSocketAddress(addr.getHostName(), addr.getPort()), connTimeout);
}
catch (Exception e) {
if (ch != null) {
if (ch.socket() != null) {
try {
ch.socket().close();
}
catch (Exception ignored) {
// ignore close exception
}
}

try {
ch.close();
}
catch (Exception ignored) {
// ignore close exception
}
}
throw new ClientConnectionException(e.getMessage(), e);
}

Map<Integer, Object> meta = new HashMap<>();
GridNioFuture<?> sslHandshakeFut = null;
Expand Down

0 comments on commit eb57f7d

Please sign in to comment.