Skip to content

Commit 4821552

Browse files
committed
Fixed proxy server being in an inconsistent state when an error occurred
1 parent ad907da commit 4821552

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main/java/net/raphimc/viaproxy/ViaProxy.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,14 @@ public static void startProxy() {
137137
if (currentProxyServer != null) {
138138
throw new IllegalStateException("Proxy is already running");
139139
}
140-
currentProxyServer = new NetServer(Client2ProxyHandler::new, Client2ProxyChannelInitializer::new);
141-
Logger.LOGGER.info("Binding proxy server to " + Options.BIND_ADDRESS + ":" + Options.BIND_PORT);
142-
currentProxyServer.bind(Options.BIND_ADDRESS, Options.BIND_PORT, false);
140+
try {
141+
currentProxyServer = new NetServer(Client2ProxyHandler::new, Client2ProxyChannelInitializer::new);
142+
Logger.LOGGER.info("Binding proxy server to " + Options.BIND_ADDRESS + ":" + Options.BIND_PORT);
143+
currentProxyServer.bind(Options.BIND_ADDRESS, Options.BIND_PORT, false);
144+
} catch (Throwable e) {
145+
currentProxyServer = null;
146+
throw e;
147+
}
143148
}
144149

145150
public static void stopProxy() {

0 commit comments

Comments
 (0)