From d9b80ac2bba00737603daca0fb0d2b4de0f59991 Mon Sep 17 00:00:00 2001 From: Julian Yerfino Date: Tue, 13 Sep 2016 12:36:02 -0300 Subject: [PATCH 1/2] Allow closing the connection if state is OPEN or CONNECTING --- modules/javascript/src/main/webapp/javascript/atmosphere.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/javascript/src/main/webapp/javascript/atmosphere.js b/modules/javascript/src/main/webapp/javascript/atmosphere.js index f29b841f..cbbf852b 100644 --- a/modules/javascript/src/main/webapp/javascript/atmosphere.js +++ b/modules/javascript/src/main/webapp/javascript/atmosphere.js @@ -519,7 +519,7 @@ _activeRequest = null; } if (_websocket != null) { - if (_websocket.canSendMessage) { + if (_websocket.readyState === 0 || _websocket.readyState === 1) { _debug("invoking .close() on WebSocket object"); _websocket.close(); } From a4ecbfeb314ec765dfe3cede6482ff912fe164d6 Mon Sep 17 00:00:00 2001 From: Julian Yerfino Date: Thu, 2 Feb 2017 17:49:53 -0300 Subject: [PATCH 2/2] Allow recover if there are 2 messages on the same frame but only the first one with proper length --- .../javascript/src/main/webapp/javascript/atmosphere.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/javascript/src/main/webapp/javascript/atmosphere.js b/modules/javascript/src/main/webapp/javascript/atmosphere.js index dda2bd53..b35afb0e 100644 --- a/modules/javascript/src/main/webapp/javascript/atmosphere.js +++ b/modules/javascript/src/main/webapp/javascript/atmosphere.js @@ -519,7 +519,7 @@ _activeRequest = null; } if (_websocket != null) { - if (_websocket.readyState === 0 || _websocket.readyState === 1) { + if (_websocket.canSendMessage) { _debug("invoking .close() on WebSocket object"); _websocket.close(); } @@ -1688,8 +1688,11 @@ while (messageStart !== -1) { var str = message.substring(0, messageStart); var messageLength = +str; - if (isNaN(messageLength)) + if (isNaN(messageLength)) { + // Discard partial message, otherwise it would never recover from this condition + response.partialMessage = ''; throw new Error('message length "' + str + '" is not a number'); + } messageStart += request.messageDelimiter.length; if (messageStart + messageLength > message.length) { // message not complete, so there is no trailing messageDelimiter