Ignore incoming events for rooms that we have left #2490
Conversation
When synapse receives an event for a room its not in over federation, it double checks with the remote server to see if it is in fact in the room. This is done so that if the server has forgotten about the room (usually as a result of the database being dropped) it can recover from it. However, in the presence of state resets in large rooms, this can cause a lot of work for servers that have legitimately left. As a hacky solution that supports both cases we drop incoming events for rooms that we have explicitly left. This means that we no longer support the case of servers having forgotten that they've rejoined a room, but that is sufficiently rare that we're not going to support it for now.
raise Exception("Invalid host name") | ||
|
||
defer.returnValue(True) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is almost an exact copy of is_host_joined
above.
synapse/handlers/federation.py
Outdated
if not is_in_room: | ||
was_in_room = yield self.store.was_host_joined( | ||
pdu.room_id, self.server_name, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spurious LF?
lgtm. my gut is that the auto-rejoin-rooms stuff is too magical and complicated to preserve long-term, but given it can be done easily here... why not. |
Its worth noting that the actual number of lines to support this is relatively small by the looks of things, as it reuses existing code paths. |
synapse/handlers/federation.py
Outdated
@@ -125,6 +125,28 @@ def on_receive_pdu(self, origin, pdu, get_missing=True): | |||
self.room_queues[pdu.room_id].append((pdu, origin)) | |||
return | |||
|
|||
# If we're no longer in the room just ditch the event entirely. This | |||
# is probably an old server that has come back and thinks we're still | |||
# in the room. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... or we've been rejoined to the room by a state reset.
@@ -533,6 +533,38 @@ def is_host_joined(self, room_id, host): | |||
|
|||
defer.returnValue(True) | |||
|
|||
@cachedInlineCallbacks() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
erm; do we not need to arrange for this cache to be flushed?
synapse/storage/roommember.py
Outdated
@cachedInlineCallbacks() | ||
def was_host_joined(self, room_id, host): | ||
"""Check whether the server is or ever was in the room. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
document the arg types and return types please
synapse/storage/roommember.py
Outdated
host (str) | ||
|
||
Returns: | ||
bool: whether the host is/was in the room or not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nuh. it returns a deferred.
also: "True if the host is/was in the room. Otherwise False".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm other than comment nitpickery
When synapse receives an event for a room its not in over federation, it
double checks with the remote server to see if it is in fact in the
room. This is done so that if the server has forgotten about the room
(usually as a result of the database being dropped) it can recover from
it.
However, in the presence of state resets in large rooms, this can cause
a lot of work for servers that have legitimately left. As a hacky
solution that supports both cases we drop incoming events for rooms that
we have explicitly left.
This means that we no longer support the case of servers having
forgotten that they've rejoined a room, but that is sufficiently rare
that we're not going to support it for now.