Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reattach attached channels on clean connect #396

Merged
merged 3 commits into from
Apr 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions common/lib/transport/connectionmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -684,12 +688,14 @@ 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) {
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;
}
};

Expand Down