Skip to content

Commit 63a6eb7

Browse files
committed
fix(network): handle SocketException more gracefully
1 parent 89ba054 commit 63a6eb7

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

sdk/src/server-api/sc/networking/clients/XStreamClient.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ public void receiveThread() {
138138
} else if (exceptionCause instanceof EOFException) {
139139
handleDisconnect(DisconnectCause.LOST_CONNECTION, e);
140140
} else if (exceptionCause instanceof IOException
141-
&& exceptionCause.getCause() != null && exceptionCause
142-
.getCause() instanceof InterruptedException) {
141+
&& exceptionCause.getCause() != null
142+
&& exceptionCause.getCause() instanceof InterruptedException) {
143143
handleDisconnect(DisconnectCause.LOST_CONNECTION, e);
144144
} else {
145145
handleDisconnect(DisconnectCause.PROTOCOL_ERROR, e);
@@ -201,8 +201,6 @@ protected final void handleDisconnect(DisconnectCause cause) {
201201
protected final void handleDisconnect(DisconnectCause cause, Throwable exception) {
202202
if (exception != null) {
203203
logger.warn("{} disconnected (Cause: {}, Exception: {})", this, cause, exception);
204-
if (logger.isDebugEnabled())
205-
exception.printStackTrace();
206204
} else {
207205
logger.info("{} disconnected (Cause: {})", this, cause);
208206
}
@@ -263,7 +261,7 @@ protected synchronized void close() {
263261
this.out.close();
264262
} catch (Exception e) {
265263
if (e.getCause() instanceof SocketException)
266-
logger.debug("Failed to close OUT", e);
264+
logger.debug("Can't close OUT, Socket already closed: {}", e.toString());
267265
else
268266
logger.warn("Failed to close OUT", e);
269267
}

server/test/sc/server/network/LobbyTest.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import sc.server.client.TestLobbyClientListener
66
import sc.server.gaming.GameRoom
77
import sc.server.plugins.TestPlugin
88
import sc.shared.ScoreCause
9+
import java.net.SocketException
910
import kotlin.time.ExperimentalTime
1011

1112
@ExperimentalTime
@@ -43,7 +44,10 @@ class LobbyTest: RealServerTest() {
4344
val room = gameMgr.games.single()
4445
room.isOver shouldBe false
4546

46-
player1.sendCustomData("<yarr>")
47+
try {
48+
player1.sendCustomData("<yarr>")
49+
} catch(_: SocketException) {
50+
}
4751

4852
await("Game is over") { room.isOver }
4953
await("GameResult") { room.result != null }

0 commit comments

Comments
 (0)