Terminate all threads if the server fails to bind to a port

Signed-off-by: Graham <gpe@openrs2.org>
Graham 4 years ago
parent 9b0260a3df
commit 3889c8a034
  1. 8
      game/src/main/kotlin/org/openrs2/game/GameServer.kt
  2. 1
      game/src/main/kotlin/org/openrs2/game/net/NetworkService.kt

@ -17,7 +17,13 @@ public class GameServer @Inject constructor(
serviceManager.startAsync() serviceManager.startAsync()
runtime.addShutdownHook(shutdownHook) runtime.addShutdownHook(shutdownHook)
serviceManager.awaitHealthy() try {
serviceManager.awaitHealthy()
} catch (ex: Throwable) {
serviceManager.stopAsync().awaitStopped()
runtime.removeShutdownHook(shutdownHook)
throw ex
}
val elapsed = System.nanoTime() - start val elapsed = System.nanoTime() - start
logger.info { "Started OpenRS2 in ${elapsed / NANOS_PER_MILLI} milliseconds" } logger.info { "Started OpenRS2 in ${elapsed / NANOS_PER_MILLI} milliseconds" }

@ -36,6 +36,7 @@ public class NetworkService @Inject constructor(
CompletableFuture.allOf(httpFuture, rs2PrimaryFuture, rs2SecondaryFuture).handle { _, ex -> CompletableFuture.allOf(httpFuture, rs2PrimaryFuture, rs2SecondaryFuture).handle { _, ex ->
if (ex != null) { if (ex != null) {
group.shutdownGracefully()
notifyFailed(ex) notifyFailed(ex)
} else { } else {
notifyStarted() notifyStarted()

Loading…
Cancel
Save