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

Fix sync connection serial in the event of a failed upgrade #445

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions common/lib/transport/connectionmanager.js
Expand Up @@ -332,7 +332,7 @@ var ConnectionManager = (function() {
* @param transport, the transport instance
* @param connectionKey
*/
ConnectionManager.prototype.scheduleTransportActivation = function(error, transport, connectionKey, connectionSerial, connectionId, connectionDetails) {
ConnectionManager.prototype.scheduleTransportActivation = function(error, transport, connectionKey, preUpgradeConnectionSerial, connectionId, connectionDetails) {
var self = this,
currentTransport = this.activeProtocol && this.activeProtocol.getTransport(),
abandon = function() {
Expand Down Expand Up @@ -387,14 +387,14 @@ var ConnectionManager = (function() {
* be a sync with the new connectionSerial (which will be -1). (And it
* needs to be set in the library, which is done by activateTransport). */
var connectionReset = connectionId !== self.connectionId,
newConnectionSerial = connectionReset ? connectionSerial : self.connectionSerial;
syncConnectionSerial = connectionReset ? preUpgradeConnectionSerial : self.connectionSerial;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scheduleTransportActivation() is passed the connectionSerial from the CONNECTED message when the upgrade transport connects. So how is this the preUpgradeConnectionSerial ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the sense that the sync as the atomic moment of the actual 'upgrade', so preUpgradeConnectionSerial is the serial of the upgrade transport before that (likely -1). Can change to preSyncConnectionSerial if you think that's clearer


if(connectionReset) {
Logger.logAction(Logger.LOG_ERROR, 'ConnectionManager.scheduleTransportActivation()', 'Upgrade resulted in new connectionId; resetting library connectionSerial from ' + self.connectionSerial + ' to ' + newConnectionSerial + '; upgrade error was ' + error);
}

Logger.logAction(Logger.LOG_MINOR, 'ConnectionManager.scheduleTransportActivation()', 'Syncing transport; transport = ' + transport);
self.sync(transport, function(syncErr, newConnectionSerial, connectionId) {
self.sync(transport, syncConnectionSerial, function(syncErr, newConnectionSerial, connectionId) {
/* If there's been some problem with syncing (and the connection hasn't
* closed or something in the meantime), we have a problem -- we can't
* just fall back on the old transport, as we don't know whether
Expand Down Expand Up @@ -634,7 +634,7 @@ var ConnectionManager = (function() {
* Called when activating a new transport, to ensure message delivery
* on the new transport synchronises with the messages already received
*/
ConnectionManager.prototype.sync = function(transport, callback) {
ConnectionManager.prototype.sync = function(transport, connectionSerial, callback) {
var timeout = setTimeout(function () {
transport.off('sync');
callback(new ErrorInfo('Timeout waiting for sync response', 50000, 500));
Expand All @@ -644,14 +644,14 @@ var ConnectionManager = (function() {
var syncMessage = ProtocolMessage.fromValues({
action: actions.SYNC,
connectionKey: this.connectionKey,
connectionSerial: this.connectionSerial
connectionSerial: connectionSerial
});

transport.send(syncMessage);

transport.once('sync', function(connectionSerial, connectionId) {
transport.once('sync', function(newConnectionSerial, connectionId) {
clearTimeout(timeout);
callback(null, connectionSerial, connectionId);
callback(null, newConnectionSerial, connectionId);
});
};

Expand Down