From 3889c8a0343912aac5500df801aaba046a8adb05 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 29 May 2021 23:14:05 +0100 Subject: [PATCH] Terminate all threads if the server fails to bind to a port Signed-off-by: Graham --- game/src/main/kotlin/org/openrs2/game/GameServer.kt | 8 +++++++- .../main/kotlin/org/openrs2/game/net/NetworkService.kt | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/game/src/main/kotlin/org/openrs2/game/GameServer.kt b/game/src/main/kotlin/org/openrs2/game/GameServer.kt index 37468d93f7..0ab5ceb40f 100644 --- a/game/src/main/kotlin/org/openrs2/game/GameServer.kt +++ b/game/src/main/kotlin/org/openrs2/game/GameServer.kt @@ -17,7 +17,13 @@ public class GameServer @Inject constructor( serviceManager.startAsync() runtime.addShutdownHook(shutdownHook) - serviceManager.awaitHealthy() + try { + serviceManager.awaitHealthy() + } catch (ex: Throwable) { + serviceManager.stopAsync().awaitStopped() + runtime.removeShutdownHook(shutdownHook) + throw ex + } val elapsed = System.nanoTime() - start logger.info { "Started OpenRS2 in ${elapsed / NANOS_PER_MILLI} milliseconds" } diff --git a/game/src/main/kotlin/org/openrs2/game/net/NetworkService.kt b/game/src/main/kotlin/org/openrs2/game/net/NetworkService.kt index 6d48b9cbf0..ae264def73 100644 --- a/game/src/main/kotlin/org/openrs2/game/net/NetworkService.kt +++ b/game/src/main/kotlin/org/openrs2/game/net/NetworkService.kt @@ -36,6 +36,7 @@ public class NetworkService @Inject constructor( CompletableFuture.allOf(httpFuture, rs2PrimaryFuture, rs2SecondaryFuture).handle { _, ex -> if (ex != null) { + group.shutdownGracefully() notifyFailed(ex) } else { notifyStarted()