Skip to content

Commit

Permalink
Fix exceptions from background database update for event labels. (mat…
Browse files Browse the repository at this point in the history
…rix-org#6407)

Add some exception handling here so that events whose json cannot be parsed are
ignored rather than getting us stuck in a loop.

Fixes matrix-org#6404.
  • Loading branch information
richvdh authored Nov 25, 2019
1 parent 41e4566 commit b7367c3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
1 change: 1 addition & 0 deletions changelog.d/6407.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug which could cause the background database update hander for event labels to get stuck in a loop raising exceptions.
43 changes: 25 additions & 18 deletions synapse/storage/data_stores/main/events_bg_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,24 +530,31 @@ def _event_store_labels_txn(txn):
nbrows = 0
last_row_event_id = ""
for (event_id, event_json_raw) in results:
event_json = json.loads(event_json_raw)

self._simple_insert_many_txn(
txn=txn,
table="event_labels",
values=[
{
"event_id": event_id,
"label": label,
"room_id": event_json["room_id"],
"topological_ordering": event_json["depth"],
}
for label in event_json["content"].get(
EventContentFields.LABELS, []
)
if isinstance(label, str)
],
)
try:
event_json = json.loads(event_json_raw)

self._simple_insert_many_txn(
txn=txn,
table="event_labels",
values=[
{
"event_id": event_id,
"label": label,
"room_id": event_json["room_id"],
"topological_ordering": event_json["depth"],
}
for label in event_json["content"].get(
EventContentFields.LABELS, []
)
if isinstance(label, str)
],
)
except Exception as e:
logger.warning(
"Unable to load event %s (no labels will be imported): %s",
event_id,
e,
)

nbrows += 1
last_row_event_id = event_id
Expand Down

0 comments on commit b7367c3

Please sign in to comment.