From 338d80e854c0313b6d4e57c22f144e23e2de07bc Mon Sep 17 00:00:00 2001 From: Dmytro Galiievskyi Date: Mon, 4 Feb 2019 18:16:33 +0200 Subject: [PATCH 1/2] Fix race condition on authorization --- src/centrifuge.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/centrifuge.js b/src/centrifuge.js index 5096fd7d..1173d15d 100644 --- a/src/centrifuge.js +++ b/src/centrifuge.js @@ -59,6 +59,7 @@ export class Centrifuge extends EventEmitter { this._latencyStart = null; this._connectData = null; this._token = null; + this._subscribeXhr = null; this._config = { debug: false, sockjs: null, @@ -1428,6 +1429,7 @@ export class Centrifuge extends EventEmitter { this.stopBatching(); } + this._subscribeXhr = null; }; if (this._config.onPrivateSubscribe !== null) { @@ -1435,6 +1437,11 @@ export class Centrifuge extends EventEmitter { data: data }, cb); } else { + if (this._subscribeXhr) { + this._subscribeXhr.abort(); + this._debug('Subscribe XHR request has been cancelled'); + } + this._ajax(this._config.subscribeEndpoint, this._config.subscribeParams, this._config.subscribeHeaders, data, cb); } }; From 6e3015a20323933efbd3fa5f4a73e69ea15cf3e7 Mon Sep 17 00:00:00 2001 From: Dmytro Galiievskyi Date: Tue, 5 Feb 2019 08:41:05 +0200 Subject: [PATCH 2/2] Update centrifuge.js --- src/centrifuge.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/centrifuge.js b/src/centrifuge.js index 1173d15d..cf29fe00 100644 --- a/src/centrifuge.js +++ b/src/centrifuge.js @@ -1442,7 +1442,7 @@ export class Centrifuge extends EventEmitter { this._debug('Subscribe XHR request has been cancelled'); } - this._ajax(this._config.subscribeEndpoint, this._config.subscribeParams, this._config.subscribeHeaders, data, cb); + this._subscribeXhr = this._ajax(this._config.subscribeEndpoint, this._config.subscribeParams, this._config.subscribeHeaders, data, cb); } };