diff options
author | Erik Johnston <erikj@element.io> | 2024-07-02 12:39:49 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2024-07-02 12:40:03 +0100 |
commit | 1ce59d7ba002a869ee94fbe375898cc79c6eb4d1 (patch) | |
tree | 40781e146a4bc05fd7e0fbe0bc5d2619c28b7683 /synapse/storage/util/id_generators.py | |
parent | Fix building debian packages for sid (#17389) (diff) | |
download | synapse-1ce59d7ba002a869ee94fbe375898cc79c6eb4d1.tar.xz |
Fix sync waiting for an invalid token from the "future" (#17386)
Fixes https://github.com/element-hq/synapse/issues/17274, hopefully. Basically, old versions of Synapse could advance streams without persisting anything in the DB (fixed in #17229). On restart those updates would get lost, and so the position of the stream would revert to an older position. If this happened across an upgrade to a later Synapse version which included #17215, then sync could get blocked indefinitely (until the stream advanced to the position in the token). We fix this by bounding the stream positions we'll wait for to the maximum position of the underlying stream ID generator.
Diffstat (limited to 'synapse/storage/util/id_generators.py')
-rw-r--r-- | synapse/storage/util/id_generators.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/synapse/storage/util/id_generators.py b/synapse/storage/util/id_generators.py index 48f88a6f8a..e8588f33cf 100644 --- a/synapse/storage/util/id_generators.py +++ b/synapse/storage/util/id_generators.py @@ -812,6 +812,11 @@ class MultiWriterIdGenerator(AbstractStreamIdGenerator): pos = self.get_current_token_for_writer(self._instance_name) txn.execute(sql, (self._stream_name, self._instance_name, pos)) + async def get_max_allocated_token(self) -> int: + return await self._db.runInteraction( + "get_max_allocated_token", self._sequence_gen.get_max_allocated + ) + @attr.s(frozen=True, auto_attribs=True) class _AsyncCtxManagerWrapper(Generic[T]): |