From 334cd9f40262f140cb36769b6bfaf129b6cbd386 Mon Sep 17 00:00:00 2001 From: Aleksey Malevaniy Date: Tue, 26 Aug 2014 22:26:14 +0300 Subject: [PATCH] Close the channel on manual disconnect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close the socket channel on manual disconnect() – otherwise channel remains opened and isConnected() will return true but no further request will succeed. --- .../src/de/tavendo/autobahn/WebSocketConnection.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Autobahn/src/de/tavendo/autobahn/WebSocketConnection.java b/Autobahn/src/de/tavendo/autobahn/WebSocketConnection.java index 3790240e..057b5f6e 100644 --- a/Autobahn/src/de/tavendo/autobahn/WebSocketConnection.java +++ b/Autobahn/src/de/tavendo/autobahn/WebSocketConnection.java @@ -439,7 +439,17 @@ public void handleMessage(Message msg) { final int tavendoCloseCode = (close.mCode == 1000) ? ConnectionHandler.CLOSE_NORMAL : ConnectionHandler.CLOSE_CONNECTION_LOST; onClose(tavendoCloseCode, close.mReason); - mWriter.forward(new WebSocketMessage.Close(1000)); + if (mActive) { + mWriter.forward(new WebSocketMessage.Close(1000)); + } else { + // we've initiated disconnect, so ready to close the channel + try { + mTransportChannel.close(); + } catch (IOException e) { + if (DEBUG) e.printStackTrace(); + } + } + } else if (msg.obj instanceof WebSocketMessage.ServerHandshake) {