From e4a5bf0eac27ca56a4b034915f43e5a85f2c535c Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sat, 18 Mar 2023 21:45:39 +0100 Subject: [PATCH] Don't print ClosedChannelException when we actually asked to close the connection. --- .../java/fr/pandacube/lib/ws/server/AbstractServerWS.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandalib-ws-server/src/main/java/fr/pandacube/lib/ws/server/AbstractServerWS.java b/pandalib-ws-server/src/main/java/fr/pandacube/lib/ws/server/AbstractServerWS.java index ada1a39..fd1a6f0 100644 --- a/pandalib-ws-server/src/main/java/fr/pandacube/lib/ws/server/AbstractServerWS.java +++ b/pandalib-ws-server/src/main/java/fr/pandacube/lib/ws/server/AbstractServerWS.java @@ -5,12 +5,15 @@ import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.WebSocketAdapter; import java.io.IOException; +import java.nio.channels.ClosedChannelException; import java.time.Duration; /** * Minimal implementation of a Websocket server endpoint using the Jetty Websocket API. */ public abstract class AbstractServerWS extends WebSocketAdapter implements AbstractWS { + + private boolean isClosed = false; @Override public final void onWebSocketConnect(Session sess) @@ -37,6 +40,8 @@ public abstract class AbstractServerWS extends WebSocketAdapter implements Abstr @Override public final void onWebSocketError(Throwable cause) { + if (isClosed && cause instanceof ClosedChannelException) + return; // ignore because this exception is expected when we just sent a close packet. onError(cause); } @@ -53,6 +58,7 @@ public abstract class AbstractServerWS extends WebSocketAdapter implements Abstr @Override public final void sendClose(int code, String reason) throws IOException { getSession().close(code, reason); + isClosed = true; } @Override