diff --git a/smack-websocket-java11/src/main/java/org/jivesoftware/smack/websocket/java11/Java11WebSocket.java b/smack-websocket-java11/src/main/java/org/jivesoftware/smack/websocket/java11/Java11WebSocket.java index b259a8916..df31182d4 100644 --- a/smack-websocket-java11/src/main/java/org/jivesoftware/smack/websocket/java11/Java11WebSocket.java +++ b/smack-websocket-java11/src/main/java/org/jivesoftware/smack/websocket/java11/Java11WebSocket.java @@ -1,6 +1,6 @@ /** * - * Copyright 2021 Florian Schmaus + * Copyright 2021-2023 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -139,11 +139,13 @@ public final class Java11WebSocket extends AbstractWebSocket { @Override public void disconnect(int code, String message) { - CompletableFuture completableFuture = webSocket.sendClose(code, message); try { - completableFuture.get(); + if (!webSocket.isOutputClosed()) { + CompletableFuture completableFuture = webSocket.sendClose(code, message); + completableFuture.get(); + } } catch (ExecutionException e) { - onWebSocketFailure(e); + LOGGER.log(Level.WARNING, "Failed to send final close when disconnecting " + this, e); } catch (InterruptedException e) { // This thread should never be interrupted, as it is a Smack internal thread. throw new AssertionError(e); diff --git a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/impl/AbstractWebSocket.java b/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/impl/AbstractWebSocket.java index a66990c71..bbe4ac749 100644 --- a/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/impl/AbstractWebSocket.java +++ b/smack-websocket/src/main/java/org/jivesoftware/smack/websocket/impl/AbstractWebSocket.java @@ -1,6 +1,6 @@ /** * - * Copyright 2020 Aditya Borikar, 2020-2021 Florian Schmaus + * Copyright 2020 Aditya Borikar, 2020-2023 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -156,4 +156,9 @@ public abstract class AbstractWebSocket { } public abstract SSLSession getSSLSession(); + + @Override + public final String toString() { + return getClass().getSimpleName() + "[" + connectionInternal.connection + "]"; + } }