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 * changelogpull/10611/head
parent
7de445161f
commit
2d9ca4ca77
|
@ -0,0 +1 @@
|
||||||
|
Clean up some of the federation event authentication code for clarity.
|
|
@ -396,10 +396,11 @@ class FrozenEvent(EventBase):
|
||||||
return self.__repr__()
|
return self.__repr__()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<FrozenEvent event_id=%r, type=%r, state_key=%r>" % (
|
return "<FrozenEvent event_id=%r, type=%r, state_key=%r, outlier=%s>" % (
|
||||||
self.get("event_id", None),
|
self.get("event_id", None),
|
||||||
self.get("type", None),
|
self.get("type", None),
|
||||||
self.get("state_key", None),
|
self.get("state_key", None),
|
||||||
|
self.internal_metadata.is_outlier(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1003,6 +1003,7 @@ class FederationServer(FederationBase):
|
||||||
# has started processing).
|
# has started processing).
|
||||||
while True:
|
while True:
|
||||||
async with lock:
|
async with lock:
|
||||||
|
logger.info("handling received PDU: %s", event)
|
||||||
try:
|
try:
|
||||||
await self.handler.on_receive_pdu(
|
await self.handler.on_receive_pdu(
|
||||||
origin, event, sent_to_us_directly=True
|
origin, event, sent_to_us_directly=True
|
||||||
|
|
|
@ -220,8 +220,6 @@ class FederationHandler(BaseHandler):
|
||||||
room_id = pdu.room_id
|
room_id = pdu.room_id
|
||||||
event_id = pdu.event_id
|
event_id = pdu.event_id
|
||||||
|
|
||||||
logger.info("handling received PDU: %s", pdu)
|
|
||||||
|
|
||||||
# We reprocess pdus when we have seen them only as outliers
|
# We reprocess pdus when we have seen them only as outliers
|
||||||
existing = await self.store.get_event(
|
existing = await self.store.get_event(
|
||||||
event_id, allow_none=True, allow_rejected=True
|
event_id, allow_none=True, allow_rejected=True
|
||||||
|
@ -229,14 +227,19 @@ class FederationHandler(BaseHandler):
|
||||||
|
|
||||||
# FIXME: Currently we fetch an event again when we already have it
|
# FIXME: Currently we fetch an event again when we already have it
|
||||||
# if it has been marked as an outlier.
|
# if it has been marked as an outlier.
|
||||||
|
if existing:
|
||||||
already_seen = existing and (
|
if not existing.internal_metadata.is_outlier():
|
||||||
not existing.internal_metadata.is_outlier()
|
logger.info(
|
||||||
or pdu.internal_metadata.is_outlier()
|
"Ignoring received event %s which we have already seen", event_id
|
||||||
)
|
)
|
||||||
if already_seen:
|
return
|
||||||
logger.debug("Already seen pdu")
|
if pdu.internal_metadata.is_outlier():
|
||||||
return
|
logger.info(
|
||||||
|
"Ignoring received outlier %s which we already have as an outlier",
|
||||||
|
event_id,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
logger.info("De-outliering event %s", event_id)
|
||||||
|
|
||||||
# do some initial sanity-checking of the event. In particular, make
|
# do some initial sanity-checking of the event. In particular, make
|
||||||
# sure it doesn't have hundreds of prev_events or auth_events, which
|
# sure it doesn't have hundreds of prev_events or auth_events, which
|
||||||
|
@ -331,7 +334,8 @@ class FederationHandler(BaseHandler):
|
||||||
"Found all missing prev_events",
|
"Found all missing prev_events",
|
||||||
)
|
)
|
||||||
|
|
||||||
if prevs - seen:
|
missing_prevs = prevs - seen
|
||||||
|
if missing_prevs:
|
||||||
# We've still not been able to get all of the prev_events for this event.
|
# We've still not been able to get all of the prev_events for this event.
|
||||||
#
|
#
|
||||||
# In this case, we need to fall back to asking another server in the
|
# In this case, we need to fall back to asking another server in the
|
||||||
|
@ -359,8 +363,8 @@ class FederationHandler(BaseHandler):
|
||||||
if sent_to_us_directly:
|
if sent_to_us_directly:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Rejecting: failed to fetch %d prev events: %s",
|
"Rejecting: failed to fetch %d prev events: %s",
|
||||||
len(prevs - seen),
|
len(missing_prevs),
|
||||||
shortstr(prevs - seen),
|
shortstr(missing_prevs),
|
||||||
)
|
)
|
||||||
raise FederationError(
|
raise FederationError(
|
||||||
"ERROR",
|
"ERROR",
|
||||||
|
@ -373,9 +377,10 @@ class FederationHandler(BaseHandler):
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"Event %s is missing prev_events: calculating state for a "
|
"Event %s is missing prev_events %s: calculating state for a "
|
||||||
"backwards extremity",
|
"backwards extremity",
|
||||||
event_id,
|
event_id,
|
||||||
|
shortstr(missing_prevs),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Calculate the state after each of the previous events, and
|
# Calculate the state after each of the previous events, and
|
||||||
|
@ -393,7 +398,7 @@ class FederationHandler(BaseHandler):
|
||||||
|
|
||||||
# Ask the remote server for the states we don't
|
# Ask the remote server for the states we don't
|
||||||
# know about
|
# know about
|
||||||
for p in prevs - seen:
|
for p in missing_prevs:
|
||||||
logger.info("Requesting state after missing prev_event %s", p)
|
logger.info("Requesting state after missing prev_event %s", p)
|
||||||
|
|
||||||
with nested_logging_context(p):
|
with nested_logging_context(p):
|
||||||
|
@ -556,21 +561,14 @@ class FederationHandler(BaseHandler):
|
||||||
logger.warning("Failed to get prev_events: %s", e)
|
logger.warning("Failed to get prev_events: %s", e)
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.info(
|
logger.info("Got %d prev_events", len(missing_events))
|
||||||
"Got %d prev_events: %s",
|
|
||||||
len(missing_events),
|
|
||||||
shortstr(missing_events),
|
|
||||||
)
|
|
||||||
|
|
||||||
# We want to sort these by depth so we process them and
|
# We want to sort these by depth so we process them and
|
||||||
# tell clients about them in order.
|
# tell clients about them in order.
|
||||||
missing_events.sort(key=lambda x: x.depth)
|
missing_events.sort(key=lambda x: x.depth)
|
||||||
|
|
||||||
for ev in missing_events:
|
for ev in missing_events:
|
||||||
logger.info(
|
logger.info("Handling received prev_event %s", ev)
|
||||||
"Handling received prev_event %s",
|
|
||||||
ev.event_id,
|
|
||||||
)
|
|
||||||
with nested_logging_context(ev.event_id):
|
with nested_logging_context(ev.event_id):
|
||||||
try:
|
try:
|
||||||
await self.on_receive_pdu(origin, ev, sent_to_us_directly=False)
|
await self.on_receive_pdu(origin, ev, sent_to_us_directly=False)
|
||||||
|
@ -1762,10 +1760,8 @@ class FederationHandler(BaseHandler):
|
||||||
for p, origin in room_queue:
|
for p, origin in room_queue:
|
||||||
try:
|
try:
|
||||||
logger.info(
|
logger.info(
|
||||||
"Processing queued PDU %s which was received "
|
"Processing queued PDU %s which was received while we were joining",
|
||||||
"while we were joining %s",
|
p,
|
||||||
p.event_id,
|
|
||||||
p.room_id,
|
|
||||||
)
|
)
|
||||||
with nested_logging_context(p.event_id):
|
with nested_logging_context(p.event_id):
|
||||||
await self.on_receive_pdu(origin, p, sent_to_us_directly=True)
|
await self.on_receive_pdu(origin, p, sent_to_us_directly=True)
|
||||||
|
|
Loading…
Reference in New Issue