diff --git a/synapse/storage/util/id_generators.py b/synapse/storage/util/id_generators.py index 46bb753bb015..7911d1841f96 100644 --- a/synapse/storage/util/id_generators.py +++ b/synapse/storage/util/id_generators.py @@ -726,10 +726,6 @@ def get_current_token_for_writer(self, instance_name: str) -> int: instance_name, self._persisted_upto_position ) - max_pos = max( - self._current_positions.values(), default=self._persisted_upto_position - ) - # We want to return the maximum "current token" that we can for a # writer, this helps ensure that streams progress as fast as # possible. @@ -737,17 +733,17 @@ def get_current_token_for_writer(self, instance_name: str) -> int: if ( self._instance_name == instance_name - and self._in_flight_fetches - and self._unfinished_ids + and not self._in_flight_fetches + and not self._unfinished_ids ): # For our own instance when there's nothing in flight, it's safe # to advance to the maximum persisted position we've seen (as we # know that any new tokens we request will be greater). - max_pos = max( + max_pos_of_all_writers = max( self._current_positions.values(), default=self._persisted_upto_position, ) - pos = max(pos, max_pos) + pos = max(pos, max_pos_of_all_writers) return self._return_factor * pos