From 2da1a3de9ab1fb4883c5a9851f4cd5a0e493cd70 Mon Sep 17 00:00:00 2001 From: MaximZaitsev Date: Thu, 28 Jul 2016 12:32:23 +0300 Subject: [PATCH] fix resources leak --- server/src/main/java/ServerMain.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/ServerMain.kt b/server/src/main/java/ServerMain.kt index 658d51a5352..1003c314471 100644 --- a/server/src/main/java/ServerMain.kt +++ b/server/src/main/java/ServerMain.kt @@ -123,9 +123,10 @@ fun getCarServerThread(): Thread { val bossGroup = NioEventLoopGroup(1) val workerGroup = NioEventLoopGroup() val b = ServerBootstrap() + val initializer = car.server.Initializer(handlerThreadsCount) b.group(bossGroup, workerGroup) .channel(NioServerSocketChannel().javaClass) - .childHandler(car.server.Initializer(handlerThreadsCount)) + .childHandler(initializer) try { val channel = b.bind(carServerPort).sync().channel() @@ -135,6 +136,7 @@ fun getCarServerThread(): Thread { } finally { bossGroup.shutdownGracefully() workerGroup.shutdownGracefully() + initializer.group.shutdownGracefully() } }) } @@ -145,9 +147,10 @@ fun getWebServerThread(): Thread { val bossGroup = NioEventLoopGroup(1) val workerGroup = NioEventLoopGroup() val b = ServerBootstrap() + val initializer = web.server.Initializer(handlerThreadsCount) b.group(bossGroup, workerGroup) .channel(NioServerSocketChannel().javaClass) - .childHandler(web.server.Initializer(handlerThreadsCount)) + .childHandler(initializer) try { val channel = b.bind(webServerPort).sync().channel() @@ -157,6 +160,7 @@ fun getWebServerThread(): Thread { } finally { bossGroup.shutdownGracefully() workerGroup.shutdownGracefully() + initializer.group.shutdownGracefully() } }) }