diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/gpgnet/GPGNetServer.java b/ice-adapter/src/main/java/com/faforever/iceadapter/gpgnet/GPGNetServer.java index e46a04f..4895565 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/gpgnet/GPGNetServer.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/gpgnet/GPGNetServer.java @@ -68,8 +68,8 @@ public void init(int gpgnetPort, int lobbyPort) { log.info("Using LOBBY_PORT: {}", this.lobbyPort); } - try (ServerSocket Socket = new ServerSocket(gpgnetPort)) { - this.serverSocket = Socket; + try { + this.serverSocket = new ServerSocket(gpgnetPort); } catch (IOException e) { log.error("Couldn't start GPGNetServer", e); IceAdapter.close(-1); @@ -241,7 +241,11 @@ private void onGpgnetConnectionLost() { private void acceptThread() { while (!Thread.currentThread().isInterrupted()) { log.info("Listening for incoming connections from game"); - try (Socket socket = serverSocket.accept()) { + try { + // The socket declaration must not be moved into a try-with-resources block, as the socket must not be + // closed. It is passed into the GPGNetClient. + Socket socket = serverSocket.accept(); + LockUtil.executeWithLock(lockSocket, () -> { if (currentClient != null) { onGpgnetConnectionLost();