Skip to content

Commit

Permalink
Fix bug on closing GPGNet socket right away
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Dec 9, 2024
1 parent c67dff3 commit 10be8db
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 10be8db

Please sign in to comment.