Skip to content

Commit

Permalink
Handle multiple rows device inbox (#17362)
Browse files Browse the repository at this point in the history
Fix bug where we don't get new to-device from remote if they resent a
message we've already persisted and have recorded in the DB twice.

`device_federation_inbox` table doesn't have a unique index, and so we
can race and store an entry in there twice. If we do so then
`simple_select_one_txn` will throw an error due to the query returning
more than one row. We should add an unique index, but it doesn't really
matter so lets just handle the case of multiple rows correctly for now.
  • Loading branch information
erikjohnston committed Jun 27, 2024
1 parent 7c169f4 commit cc5e589
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/17362.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix rare race which causes no new to-device messages to be received from remote server.
5 changes: 2 additions & 3 deletions synapse/storage/databases/main/deviceinbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,14 +825,13 @@ def add_messages_txn(
# Check if we've already inserted a matching message_id for that
# origin. This can happen if the origin doesn't receive our
# acknowledgement from the first time we received the message.
already_inserted = self.db_pool.simple_select_one_txn(
already_inserted = self.db_pool.simple_select_list_txn(
txn,
table="device_federation_inbox",
keyvalues={"origin": origin, "message_id": message_id},
retcols=("message_id",),
allow_none=True,
)
if already_inserted is not None:
if already_inserted:
return

# Add an entry for this message_id so that we know we've processed
Expand Down

0 comments on commit cc5e589

Please sign in to comment.