Skip to content

Commit

Permalink
OF-2559 Ensure NioEventLoopGroup is closed for outbound S2S
Browse files Browse the repository at this point in the history
We were seeing resource limit issues (too many open files) when running Outgoing S2S tests. This was caused by the outbound session initialisation failing to clean up its NioEventLoopGroup in many scenarios.
  • Loading branch information
viv committed Jul 27, 2023
1 parent c095508 commit b25f6ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class NettySessionInitializer {
private final DomainPair domainPair;
private final int port;
private boolean directTLS = false;
private EventLoopGroup workerGroup;
private final EventLoopGroup workerGroup;
private final ExecutorService executor = Executors.newSingleThreadExecutor();
private Channel channel;

Expand Down Expand Up @@ -118,6 +118,9 @@ public boolean exceptionOccurredForDirectTLS(Throwable cause) {

this.channel = b.connect(socketAddress).sync().channel();

// Make sure we free up resources (worker group NioEventLoopGroup) when the channel is closed
this.channel.closeFuture().addListener(future -> stop());

// Start the session negotiation
sendOpeningStreamHeader(channel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,10 @@ static LocalOutgoingServerSession createOutgoingSession(@Nonnull final DomainPai
// Wait for the future to give us a session...
// Set a read timeout so that we don't keep waiting forever
return (LocalOutgoingServerSession) sessionInitialiser.init(listenerConfiguration).get(INITIALISE_TIMEOUT_SECONDS.getValue().getSeconds(), TimeUnit.SECONDS);
} catch (ExecutionException e) {
} catch (Exception e) {
// This might be RFC6120, section 5.4.2.2 "Failure Case" or even an unrelated problem. Handle 'normally'.
log.warn("An exception occurred while creating an encrypted session. Closing connection.", e);
sessionInitialiser.stop();
return null;
} catch (TimeoutException e) {
log.warn("Timed out waiting for session creation. Closing connection.", e);
sessionInitialiser.stop();
} catch (InterruptedException e) {
log.warn("An exception occurred while creating an encrypted session. Closing connection.", e);
log.warn("An exception occurred while creating a session. Closing connection.", e);
} finally {
sessionInitialiser.stop();
}

Expand Down

0 comments on commit b25f6ba

Please sign in to comment.