summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2020-05-04 17:14:16 +0100
committerAndrew Morgan <andrew@amorgan.xyz>2020-05-04 17:14:16 +0100
commitbfc287b5c6eda4e4db0170b23a707b742398eba2 (patch)
tree0bee8891a58df3460968c29ca7783c94d836b035 /synapse/handlers
parentConvert the room handler to async/await. (#7396) (diff)
downloadsynapse-anoa/locally_rejected_invites_fix.tar.xz
Diffstat (limited to 'synapse/handlers')
-rw-r--r--synapse/handlers/federation.py26
-rw-r--r--synapse/handlers/room_member.py23
2 files changed, 25 insertions, 24 deletions
diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py
index 4e5c645525..2b19c2a784 100644
--- a/synapse/handlers/federation.py
+++ b/synapse/handlers/federation.py
@@ -1547,7 +1547,7 @@ class FederationHandler(BaseHandler):
 
     async def do_remotely_reject_invite(
         self, target_hosts: Iterable[str], room_id: str, user_id: str, content: JsonDict
-    ) -> EventBase:
+    ) -> Optional[EventBase]:
         origin, event, room_version = await self._make_and_verify_event(
             target_hosts, room_id, user_id, "leave", content=content
         )
@@ -1564,12 +1564,26 @@ class FederationHandler(BaseHandler):
         except ValueError:
             pass
 
-        await self.federation_client.send_leave(target_hosts, event)
-
-        context = await self.state_handler.compute_event_context(event)
-        await self.persist_events_and_notify([(event, context)])
+        try:
+            await self.federation_client.send_leave(target_hosts, event)
+            return event
+        except Exception as e:
+            # if we were unable to reject the exception, just mark
+            # it as rejected on our end and plough ahead.
+            #
+            # The 'except' clause is very broad, but we need to
+            # capture everything from DNS failures upwards
+            #
+            logger.warning("Failed to reject invite: %s", e)
 
-        return event
+            await self.store.locally_reject_invite(user_id, room_id)
+            return None
+        finally:
+            # This block will always run before returning, and will return with
+            # whatever value was returned in the try/except blocks
+            # (it will not, for example, be over-written by None)
+            context = await self.state_handler.compute_event_context(event)
+            await self.persist_events_and_notify([(event, context)])
 
     async def _make_and_verify_event(
         self,
diff --git a/synapse/handlers/room_member.py b/synapse/handlers/room_member.py
index 53b49bc15f..d9b244c331 100644
--- a/synapse/handlers/room_member.py
+++ b/synapse/handlers/room_member.py
@@ -976,25 +976,12 @@ class RoomMemberMasterHandler(RoomMemberHandler):
     ):
         """Implements RoomMemberHandler._remote_reject_invite
         """
-        fed_handler = self.federation_handler
-        try:
-            ret = yield defer.ensureDeferred(
-                fed_handler.do_remotely_reject_invite(
-                    remote_room_hosts, room_id, target.to_string(), content=content,
-                )
+        ret = yield defer.ensureDeferred(
+            self.federation_handler.do_remotely_reject_invite(
+                remote_room_hosts, room_id, target.to_string(), content=content,
             )
-            return ret
-        except Exception as e:
-            # if we were unable to reject the exception, just mark
-            # it as rejected on our end and plough ahead.
-            #
-            # The 'except' clause is very broad, but we need to
-            # capture everything from DNS failures upwards
-            #
-            logger.warning("Failed to reject invite: %s", e)
-
-            yield self.store.locally_reject_invite(target.to_string(), room_id)
-            return {}
+        )
+        return ret if ret else {}
 
     def _user_joined_room(self, target, room_id):
         """Implements RoomMemberHandler._user_joined_room