From 39682ee1a1e0bb22d636e024c654acf751624458 Mon Sep 17 00:00:00 2001 From: Simon Woolf Date: Tue, 4 Apr 2017 18:25:39 +0100 Subject: [PATCH 1/3] Reattach attached channels on clean connect --- common/lib/transport/connectionmanager.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/common/lib/transport/connectionmanager.js b/common/lib/transport/connectionmanager.js index 172f83408c..dcdc245ec4 100644 --- a/common/lib/transport/connectionmanager.js +++ b/common/lib/transport/connectionmanager.js @@ -651,8 +651,12 @@ var ConnectionManager = (function() { * on a new connection, with implications for msgSerial and channel state */ var self = this; connectionSerial = (connectionSerial === undefined) ? -1 : connectionSerial; - if(this.connectionId && this.connectionId !== connectionId) { - Logger.logAction(Logger.LOG_MINOR, 'ConnectionManager.setConnection()', 'connectionId has changed; resetting msgSerial and reattaching channels'); + /* Note that this is also run on clean connections; the msgSerial is a + * noop, but the channel reattach is needed for channels that were + * previously in the attached state even though the connection mode was + * 'clean' due to a freshness check - see https://github.com/ably/ably-js/issues/394 */ + if(this.connectionId !== connectionId) { + Logger.logAction(Logger.LOG_MINOR, 'ConnectionManager.setConnection()', 'New connectionId; resetting msgSerial and reattaching any attached channels'); this.msgSerial = 0; /* Wait till next tick before reattaching channels, so that connection * state will be updated and so that it will be applied after From f5a4f0d4abf4720b46025653413268c86827aa65 Mon Sep 17 00:00:00 2001 From: Simon Woolf Date: Tue, 4 Apr 2017 18:26:33 +0100 Subject: [PATCH 2/3] No need to recheck freshness if no connection state --- common/lib/transport/connectionmanager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/lib/transport/connectionmanager.js b/common/lib/transport/connectionmanager.js index dcdc245ec4..702b8cdb19 100644 --- a/common/lib/transport/connectionmanager.js +++ b/common/lib/transport/connectionmanager.js @@ -688,7 +688,7 @@ var ConnectionManager = (function() { }; ConnectionManager.prototype.checkConnectionStateFreshness = function() { - if(!this.lastActivity) { return; } + if(!this.lastActivity || !this.connectionId) { return; } var sinceLast = Utils.now() - this.lastActivity; if(sinceLast > this.connectionStateTtl + this.maxIdleInterval) { From 6f26b6ec31f8c584b2c922bf0fdde8b3de0fd64c Mon Sep 17 00:00:00 2001 From: Simon Woolf Date: Tue, 4 Apr 2017 18:27:11 +0100 Subject: [PATCH 3/3] Set connecting failstate to suspended after failed freshness check --- common/lib/transport/connectionmanager.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/lib/transport/connectionmanager.js b/common/lib/transport/connectionmanager.js index 702b8cdb19..c90c9517a7 100644 --- a/common/lib/transport/connectionmanager.js +++ b/common/lib/transport/connectionmanager.js @@ -694,6 +694,8 @@ var ConnectionManager = (function() { if(sinceLast > this.connectionStateTtl + this.maxIdleInterval) { Logger.logAction(Logger.LOG_MINOR, 'ConnectionManager.checkConnectionStateFreshness()', 'Last known activity from realtime was ' + sinceLast + 'ms ago; discarding connection state'); this.clearConnection(); + this.states.connecting.failState = 'suspended'; + this.states.connecting.queueEvents = false; } };