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

Commit 2d9ca4c

Browse files
authored
Clean up some logging in the federation event handler (#10591)
* Include outlier status in `str(event)` In places where we log event objects, knowing whether or not you're dealing with an outlier is super useful. * Remove duplicated logging in get_missing_events When we process events received from get_missing_events, we log them twice (once in `_get_missing_events_for_pdu`, and once in `on_receive_pdu`). Reduce the duplication by removing the logging in `on_receive_pdu`, and ensuring the call sites do sensible logging. * log in `on_receive_pdu` when we already have the event * Log which prev_events we are missing * changelog
1 parent 7de4451 commit 2d9ca4c

File tree

4 files changed

+28
-29
lines changed

4 files changed

+28
-29
lines changed

changelog.d/10591.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clean up some of the federation event authentication code for clarity.

synapse/events/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,11 @@ def __str__(self):
396396
return self.__repr__()
397397

398398
def __repr__(self):
399-
return "<FrozenEvent event_id=%r, type=%r, state_key=%r>" % (
399+
return "<FrozenEvent event_id=%r, type=%r, state_key=%r, outlier=%s>" % (
400400
self.get("event_id", None),
401401
self.get("type", None),
402402
self.get("state_key", None),
403+
self.internal_metadata.is_outlier(),
403404
)
404405

405406

synapse/federation/federation_server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ async def _process_incoming_pdus_in_room_inner(
10031003
# has started processing).
10041004
while True:
10051005
async with lock:
1006+
logger.info("handling received PDU: %s", event)
10061007
try:
10071008
await self.handler.on_receive_pdu(
10081009
origin, event, sent_to_us_directly=True

synapse/handlers/federation.py

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -220,23 +220,26 @@ async def on_receive_pdu(
220220
room_id = pdu.room_id
221221
event_id = pdu.event_id
222222

223-
logger.info("handling received PDU: %s", pdu)
224-
225223
# We reprocess pdus when we have seen them only as outliers
226224
existing = await self.store.get_event(
227225
event_id, allow_none=True, allow_rejected=True
228226
)
229227

230228
# FIXME: Currently we fetch an event again when we already have it
231229
# if it has been marked as an outlier.
232-
233-
already_seen = existing and (
234-
not existing.internal_metadata.is_outlier()
235-
or pdu.internal_metadata.is_outlier()
236-
)
237-
if already_seen:
238-
logger.debug("Already seen pdu")
239-
return
230+
if existing:
231+
if not existing.internal_metadata.is_outlier():
232+
logger.info(
233+
"Ignoring received event %s which we have already seen", event_id
234+
)
235+
return
236+
if pdu.internal_metadata.is_outlier():
237+
logger.info(
238+
"Ignoring received outlier %s which we already have as an outlier",
239+
event_id,
240+
)
241+
return
242+
logger.info("De-outliering event %s", event_id)
240243

241244
# do some initial sanity-checking of the event. In particular, make
242245
# sure it doesn't have hundreds of prev_events or auth_events, which
@@ -331,7 +334,8 @@ async def on_receive_pdu(
331334
"Found all missing prev_events",
332335
)
333336

334-
if prevs - seen:
337+
missing_prevs = prevs - seen
338+
if missing_prevs:
335339
# We've still not been able to get all of the prev_events for this event.
336340
#
337341
# In this case, we need to fall back to asking another server in the
@@ -359,8 +363,8 @@ async def on_receive_pdu(
359363
if sent_to_us_directly:
360364
logger.warning(
361365
"Rejecting: failed to fetch %d prev events: %s",
362-
len(prevs - seen),
363-
shortstr(prevs - seen),
366+
len(missing_prevs),
367+
shortstr(missing_prevs),
364368
)
365369
raise FederationError(
366370
"ERROR",
@@ -373,9 +377,10 @@ async def on_receive_pdu(
373377
)
374378

375379
logger.info(
376-
"Event %s is missing prev_events: calculating state for a "
380+
"Event %s is missing prev_events %s: calculating state for a "
377381
"backwards extremity",
378382
event_id,
383+
shortstr(missing_prevs),
379384
)
380385

381386
# Calculate the state after each of the previous events, and
@@ -393,7 +398,7 @@ async def on_receive_pdu(
393398

394399
# Ask the remote server for the states we don't
395400
# know about
396-
for p in prevs - seen:
401+
for p in missing_prevs:
397402
logger.info("Requesting state after missing prev_event %s", p)
398403

399404
with nested_logging_context(p):
@@ -556,21 +561,14 @@ async def _get_missing_events_for_pdu(
556561
logger.warning("Failed to get prev_events: %s", e)
557562
return
558563

559-
logger.info(
560-
"Got %d prev_events: %s",
561-
len(missing_events),
562-
shortstr(missing_events),
563-
)
564+
logger.info("Got %d prev_events", len(missing_events))
564565

565566
# We want to sort these by depth so we process them and
566567
# tell clients about them in order.
567568
missing_events.sort(key=lambda x: x.depth)
568569

569570
for ev in missing_events:
570-
logger.info(
571-
"Handling received prev_event %s",
572-
ev.event_id,
573-
)
571+
logger.info("Handling received prev_event %s", ev)
574572
with nested_logging_context(ev.event_id):
575573
try:
576574
await self.on_receive_pdu(origin, ev, sent_to_us_directly=False)
@@ -1762,10 +1760,8 @@ async def _handle_queued_pdus(
17621760
for p, origin in room_queue:
17631761
try:
17641762
logger.info(
1765-
"Processing queued PDU %s which was received "
1766-
"while we were joining %s",
1767-
p.event_id,
1768-
p.room_id,
1763+
"Processing queued PDU %s which was received while we were joining",
1764+
p,
17691765
)
17701766
with nested_logging_context(p.event_id):
17711767
await self.on_receive_pdu(origin, p, sent_to_us_directly=True)

0 commit comments

Comments
 (0)