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

Fix handling of failures when calling /event_auth. #5317

Merged
merged 3 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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/5317.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix handling of failures when processing incoming events where calling `/event_auth` on remote server fails.
50 changes: 38 additions & 12 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
CodeMessageException,
FederationDeniedError,
FederationError,
RequestSendFailed,
StoreError,
SynapseError,
)
Expand Down Expand Up @@ -2027,9 +2028,15 @@ def do_auth(self, origin, event, context, auth_events):
"""
room_version = yield self.store.get_room_version(event.room_id)

yield self._update_auth_events_and_context_for_auth(
origin, event, context, auth_events
)
try:
yield self._update_auth_events_and_context_for_auth(
origin, event, context, auth_events
)
except Exception:
# We don't really mind if the above fails, so lets not fail
# processing if it does.
logger.exception("Failed to call _update_auth_events_and_context_for_auth")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we really log a full stacktrace here? they look incredibly scary in the logs when they happen, so if it's something that we don't count as an error, we shouldn't log the stacktrace. just logger.warning with the type and value of the exception.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe. We shouldn't have any expected exceptions (now), so I'm slightly worried about not having the stack trace at all.


try:
self.auth.check(room_version, event, auth_events=auth_events)
except AuthError as e:
Expand All @@ -2042,6 +2049,15 @@ def _update_auth_events_and_context_for_auth(
):
"""Helper for do_auth. See there for docs.

Checks whether a given event has the expected auth events. If it
doesn't then we talk to the remote server to compare state to see if
we can come to a consensus (e.g. if one server missed some valid
state).

This attempts to resovle any potential divergence of state between
servers, but is not essential and so failures should not block further
processing of the event.

Args:
origin (str):
event (synapse.events.EventBase):
Expand Down Expand Up @@ -2088,9 +2104,14 @@ def _update_auth_events_and_context_for_auth(
missing_auth,
)
try:
remote_auth_chain = yield self.federation_client.get_event_auth(
origin, event.room_id, event.event_id
)
try:
remote_auth_chain = yield self.federation_client.get_event_auth(
origin, event.room_id, event.event_id
)
except RequestSendFailed:
# The other side isn't around or doesn't implement the
# endpoint, so lets just bail out.
return
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved

seen_remotes = yield self.store.have_seen_events(
[e.event_id for e in remote_auth_chain]
Expand Down Expand Up @@ -2236,12 +2257,17 @@ def _update_auth_events_and_context_for_auth(

try:
# 2. Get remote difference.
result = yield self.federation_client.query_auth(
origin,
event.room_id,
event.event_id,
local_auth_chain,
)
try:
result = yield self.federation_client.query_auth(
origin,
event.room_id,
event.event_id,
local_auth_chain,
)
except RequestSendFailed:
# The other side isn't around or doesn't implement the
# endpoint, so lets just bail out.
return
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved

seen_remotes = yield self.store.have_seen_events(
[e.event_id for e in result["auth_chain"]]
Expand Down