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

Fix exception when a cross-signed device is deleted #6462

Merged
merged 2 commits into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6462.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug which lead to exceptions being thrown in a loop when a cross-signed device is deleted.
23 changes: 19 additions & 4 deletions synapse/storage/data_stores/main/end_to_end_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,28 @@ def _get_e2e_device_keys_txn(
txn.execute(signature_sql, signature_query_params)
rows = self.cursor_to_dict(txn)

# add each cross-signing signature to the correct device in the result dict.
for row in rows:
signing_user_id = row["user_id"]
signing_key_id = row["key_id"]
target_user_id = row["target_user_id"]
target_device_id = row["target_device_id"]
if target_user_id in result and target_device_id in result[target_user_id]:
result[target_user_id][target_device_id].setdefault(
"signatures", {}
).setdefault(row["user_id"], {})[row["key_id"]] = row["signature"]
signature = row["signature"]

target_user_result = result.get(target_user_id)
if not target_user_result:
continue

target_device_result = target_user_result.get(target_device_id)
if not target_device_result:
# note that target_device_result will be None for deleted devices.
continue

target_device_signatures = target_device_result.setdefault("signatures", {})
signing_user_signatures = target_device_signatures.setdefault(
signing_user_id, {}
)
signing_user_signatures[signing_key_id] = signature

log_kv(result)
return result
Expand Down