From 482155250d0154b52be0b429ba34d74487cdb4c0 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Mon, 9 Jan 2023 21:40:56 +0100 Subject: [PATCH] Fixed proxy server being in an inconsistent state when an error occurred --- src/main/java/net/raphimc/viaproxy/ViaProxy.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/raphimc/viaproxy/ViaProxy.java b/src/main/java/net/raphimc/viaproxy/ViaProxy.java index b7307e5..d5ef6aa 100644 --- a/src/main/java/net/raphimc/viaproxy/ViaProxy.java +++ b/src/main/java/net/raphimc/viaproxy/ViaProxy.java @@ -137,9 +137,14 @@ public class ViaProxy { if (currentProxyServer != null) { throw new IllegalStateException("Proxy is already running"); } - currentProxyServer = new NetServer(Client2ProxyHandler::new, Client2ProxyChannelInitializer::new); - Logger.LOGGER.info("Binding proxy server to " + Options.BIND_ADDRESS + ":" + Options.BIND_PORT); - currentProxyServer.bind(Options.BIND_ADDRESS, Options.BIND_PORT, false); + try { + currentProxyServer = new NetServer(Client2ProxyHandler::new, Client2ProxyChannelInitializer::new); + Logger.LOGGER.info("Binding proxy server to " + Options.BIND_ADDRESS + ":" + Options.BIND_PORT); + currentProxyServer.bind(Options.BIND_ADDRESS, Options.BIND_PORT, false); + } catch (Throwable e) { + currentProxyServer = null; + throw e; + } } public static void stopProxy() {