summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2021-01-22 19:44:08 +0000
committerGitHub <noreply@github.com>2021-01-22 19:44:08 +0000
commit056327457ff471495741a539e99c840ed54afccd (patch)
tree5610162fa592de2044da062ba5a836d9329e2fa0
parentBump psycopg2 version (#9204) (diff)
downloadsynapse-056327457ff471495741a539e99c840ed54afccd.tar.xz
Fix chain cover update to handle events with duplicate auth events (#9210)
-rw-r--r--changelog.d/9210.bugfix1
-rw-r--r--synapse/util/iterutils.py2
-rw-r--r--tests/util/test_itertools.py12
3 files changed, 14 insertions, 1 deletions
diff --git a/changelog.d/9210.bugfix b/changelog.d/9210.bugfix
new file mode 100644
index 0000000000..f9e0765570
--- /dev/null
+++ b/changelog.d/9210.bugfix
@@ -0,0 +1 @@
+Fix chain cover update to handle events with duplicate auth events. Introduced in v1.26.0rc1.
diff --git a/synapse/util/iterutils.py b/synapse/util/iterutils.py
index 6ef2b008a4..8d2411513f 100644
--- a/synapse/util/iterutils.py
+++ b/synapse/util/iterutils.py
@@ -78,7 +78,7 @@ def sorted_topologically(
         if node not in degree_map:
             continue
 
-        for edge in edges:
+        for edge in set(edges):
             if edge in degree_map:
                 degree_map[node] += 1
 
diff --git a/tests/util/test_itertools.py b/tests/util/test_itertools.py
index 522c8061f9..1ef0af8e8f 100644
--- a/tests/util/test_itertools.py
+++ b/tests/util/test_itertools.py
@@ -92,3 +92,15 @@ class SortTopologically(TestCase):
         # Valid orderings are `[1, 3, 2, 4]` or `[1, 2, 3, 4]`, but we should
         # always get the same one.
         self.assertEqual(list(sorted_topologically([4, 3, 2, 1], graph)), [1, 2, 3, 4])
+
+    def test_duplicates(self):
+        "Test that a graph with duplicate edges work"
+        graph = {1: [], 2: [1, 1], 3: [2, 2], 4: [3]}  # type: Dict[int, List[int]]
+
+        self.assertEqual(list(sorted_topologically([4, 3, 2, 1], graph)), [1, 2, 3, 4])
+
+    def test_multiple_paths(self):
+        "Test that a graph with multiple paths between two nodes work"
+        graph = {1: [], 2: [1], 3: [2], 4: [3, 2, 1]}  # type: Dict[int, List[int]]
+
+        self.assertEqual(list(sorted_topologically([4, 3, 2, 1], graph)), [1, 2, 3, 4])