diff options
author | Erik Johnston <erik@matrix.org> | 2019-07-01 11:43:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-01 11:43:10 +0100 |
commit | 04196a4dae6315bcbb04067df7a6c2eef2b62090 (patch) | |
tree | 97436c1921a03247e29a0e226ca441148cd23bcd | |
parent | Make the http server handle coroutine-making REST servlets (#5475) (diff) | |
parent | Fixup comment (diff) | |
download | synapse-04196a4dae6315bcbb04067df7a6c2eef2b62090.tar.xz |
Merge pull request #5507 from matrix-org/erikj/presence_sync_tighloop
Fix sync tightloop bug.
-rw-r--r-- | changelog.d/5507.bugfix | 1 | ||||
-rw-r--r-- | synapse/handlers/presence.py | 21 |
2 files changed, 20 insertions, 2 deletions
diff --git a/changelog.d/5507.bugfix b/changelog.d/5507.bugfix new file mode 100644 index 0000000000..70452aa146 --- /dev/null +++ b/changelog.d/5507.bugfix @@ -0,0 +1 @@ +Fix bug where clients could tight loop calling `/sync` for a period. diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index 5204073a38..c80dc2eba0 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -1017,11 +1017,28 @@ class PresenceEventSource(object): if from_key is not None: from_key = int(from_key) + max_token = self.store.get_current_presence_token() + if from_key == max_token: + # This is necessary as due to the way stream ID generators work + # we may get updates that have a stream ID greater than the max + # token (e.g. max_token is N but stream generator may return + # results for N+2, due to N+1 not having finished being + # persisted yet). + # + # This is usually fine, as it just means that we may send down + # some presence updates multiple times. However, we need to be + # careful that the sync stream either actually does make some + # progress or doesn't return, otherwise clients will end up + # tight looping calling /sync due to it immediately returning + # the same token repeatedly. + # + # Hence this guard where we just return nothing so that the sync + # doesn't return. C.f. #5503. + defer.returnValue(([], max_token)) + presence = self.get_presence_handler() stream_change_cache = self.store.presence_stream_cache - max_token = self.store.get_current_presence_token() - users_interested_in = yield self._get_interested_in(user, explicit_room_id) user_ids_changed = set() |