From 654322e8961d7c4b484495933e1caae5e6ab42f4 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 5 Jun 2017 14:04:41 +0100 Subject: [PATCH] Stop peeking when a matrix client is stopped Otherwise we get very confused when the peek poll returns after the client is stopped. --- src/client.js | 3 +++ src/sync.js | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/client.js b/src/client.js index f7beb7b0c..abd65eb9d 100644 --- a/src/client.js +++ b/src/client.js @@ -2888,6 +2888,9 @@ MatrixClient.prototype.stopClient = function() { this._syncApi.stop(); this._syncApi = null; } + if (this._peekSync) { + this._peekSync.stopPeeking(); + } global.clearTimeout(this._checkTurnServersTimeoutID); }; diff --git a/src/sync.js b/src/sync.js index c2a8f8abe..bb3935ca6 100644 --- a/src/sync.js +++ b/src/sync.js @@ -329,6 +329,10 @@ SyncApi.prototype._peekPoll = function(roomId, token) { timeout: 30 * 1000, from: token, }, undefined, 50 * 1000).done(function(res) { + if (self._peekRoomId !== roomId) { + debuglog("Stopped peeking in room %s", roomId); + return; + } // We have a problem that we get presence both from /events and /sync // however, /sync only returns presence for users in rooms // you're actually joined to.