Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 3b4556c

Browse files
authored
Fix wait_for_stream_position for multiple waiters. (#8196)
This fixes a bug where having multiple callers waiting on the same stream and position will cause it to try and compare two deferreds, which fails (due to the sorted list having an entry of `Tuple[int, Deferred]`).
1 parent d58fda9 commit 3b4556c

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

changelog.d/8196.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix `wait_for_stream_position` to allow multiple waiters on same stream ID.

synapse/python_dependencies.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@
6666
"msgpack>=0.5.2",
6767
"phonenumbers>=8.2.0",
6868
"prometheus_client>=0.0.18,<0.9.0",
69-
# we use attr.validators.deep_iterable, which arrived in 19.1.0
69+
# we use attr.validators.deep_iterable, which arrived in 19.1.0 (Note:
70+
# Fedora 31 only has 19.1, so if we want to upgrade we should wait until 33
71+
# is out in November.)
7072
"attrs>=19.1.0",
7173
"netaddr>=0.7.18",
7274
"Jinja2>=2.9",

synapse/replication/tcp/client.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# limitations under the License.
1515
"""A replication client for use by synapse workers.
1616
"""
17-
import heapq
1817
import logging
1918
from typing import TYPE_CHECKING, Dict, List, Tuple
2019

@@ -219,9 +218,8 @@ async def wait_for_stream_position(
219218

220219
waiting_list = self._streams_to_waiters.setdefault(stream_name, [])
221220

222-
# We insert into the list using heapq as it is more efficient than
223-
# pushing then resorting each time.
224-
heapq.heappush(waiting_list, (position, deferred))
221+
waiting_list.append((position, deferred))
222+
waiting_list.sort(key=lambda t: t[0])
225223

226224
# We measure here to get in flight counts and average waiting time.
227225
with Measure(self._clock, "repl.wait_for_stream_position"):

0 commit comments

Comments
 (0)