From 328c0231df3067a468facff99934209ddf0fa331 Mon Sep 17 00:00:00 2001 From: Mikko Kortelainen Date: Tue, 9 Apr 2024 09:19:34 +0300 Subject: [PATCH] close clientDelegate in case connectContextFactory.create throws (#126) --- .../com/teragrep/rlp_03/client/ClientDelegate.java | 2 +- .../com/teragrep/rlp_03/client/ClientFactory.java | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/teragrep/rlp_03/client/ClientDelegate.java b/src/main/java/com/teragrep/rlp_03/client/ClientDelegate.java index 08f72f22..69595f6e 100644 --- a/src/main/java/com/teragrep/rlp_03/client/ClientDelegate.java +++ b/src/main/java/com/teragrep/rlp_03/client/ClientDelegate.java @@ -104,7 +104,7 @@ public boolean accept(FrameContext frameContext) { } @Override - public void close() throws Exception { + public void close() { LOGGER.debug("client FrameDelegate close"); } diff --git a/src/main/java/com/teragrep/rlp_03/client/ClientFactory.java b/src/main/java/com/teragrep/rlp_03/client/ClientFactory.java index 5929a8a8..ed760b8c 100644 --- a/src/main/java/com/teragrep/rlp_03/client/ClientFactory.java +++ b/src/main/java/com/teragrep/rlp_03/client/ClientFactory.java @@ -73,8 +73,16 @@ public Client open(InetSocketAddress inetSocketAddress) Consumer establishedContextConsumer = readyContextFuture::complete; ClientDelegate clientDelegate = new ClientDelegate(); - ConnectContext connectContext = connectContextFactory - .create(inetSocketAddress, clientDelegate, establishedContextConsumer); + + ConnectContext connectContext; + try { + connectContext = connectContextFactory + .create(inetSocketAddress, clientDelegate, establishedContextConsumer); + } + catch (IOException ioException) { + clientDelegate.close(); + throw ioException; + } LOGGER.debug("registering to eventLoop <{}>", eventLoop); eventLoop.register(connectContext); LOGGER.debug("registered to eventLoop <{}>", eventLoop);