Skip to content

Commit

Permalink
Close ServerChannelGroup when stopping the server (#69)
Browse files Browse the repository at this point in the history
or else the pool will not get stopped
  • Loading branch information
mchataigner authored and guillaumebort committed Nov 13, 2018
1 parent f8f5d56 commit c36999b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions core/src/main/scala/Server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,16 @@ object Server {
}
}
}
private val group: ServerChannelGroup = NIO1SocketServerGroup.fixedGroup(workerThreads = 4)
val ch =
NIO1SocketServerGroup.fixedGroup(workerThreads = 4).bind(new InetSocketAddress(address, port0), f)
group.bind(new InetSocketAddress(address, port0), f)
.getOrElse(sys.error(s"Failed to start server on port $port0"))
val socketAddress = ch.socketAddress
def stop() = ch.close()
def stop() = {
ch.close()
ch.join()
group.closeGroup
}
def apply(req: Request) = serveRequest(req)

// Keep the server alive until `stop()` is called.
Expand Down

0 comments on commit c36999b

Please sign in to comment.