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

Commit

Permalink
Merge pull request #1744 from matrix-org/matthew/timeout_get_missing_…
Browse files Browse the repository at this point in the history
…events

limit total timeout for get_missing_events to 10s
  • Loading branch information
NegativeMjark authored Jan 5, 2017
2 parents 899a3a1 + 8e82611 commit 5175094
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 3 additions & 1 deletion synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ def query_auth(self, destination, room_id, event_id, local_auth):

@defer.inlineCallbacks
def get_missing_events(self, destination, room_id, earliest_events_ids,
latest_events, limit, min_depth):
latest_events, limit, min_depth, timeout):
"""Tries to fetch events we are missing. This is called when we receive
an event without having received all of its ancestors.
Expand All @@ -721,6 +721,7 @@ def get_missing_events(self, destination, room_id, earliest_events_ids,
have all previous events for.
limit (int): Maximum number of events to return.
min_depth (int): Minimum depth of events tor return.
timeout (int): Max time to wait in ms
"""
try:
content = yield self.transport_layer.get_missing_events(
Expand All @@ -730,6 +731,7 @@ def get_missing_events(self, destination, room_id, earliest_events_ids,
latest_events=[e.event_id for e in latest_events],
limit=limit,
min_depth=min_depth,
timeout=timeout,
)

events = [
Expand Down
21 changes: 21 additions & 0 deletions synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ def on_get_missing_events(self, origin, room_id, earliest_events,
" limit: %d, min_depth: %d",
earliest_events, latest_events, limit, min_depth
)

missing_events = yield self.handler.on_get_missing_events(
origin, room_id, earliest_events, latest_events, limit, min_depth
)
Expand Down Expand Up @@ -567,13 +568,33 @@ def _handle_new_pdu(self, origin, pdu, get_missing=True):
len(prevs - seen), pdu.room_id, list(prevs - seen)[:5]
)

# XXX: we set timeout to 10s to help workaround
# https://github.com/matrix-org/synapse/issues/1733.
# The reason is to avoid holding the linearizer lock
# whilst processing inbound /send transactions, causing
# FDs to stack up and block other inbound transactions
# which empirically can currently take up to 30 minutes.
#
# N.B. this explicitly disables retry attempts.
#
# N.B. this also increases our chances of falling back to
# fetching fresh state for the room if the missing event
# can't be found, which slightly reduces our security.
# it may also increase our DAG extremity count for the room,
# causing additional state resolution? See #1760.
# However, fetching state doesn't hold the linearizer lock
# apparently.
#
# see https://github.com/matrix-org/synapse/pull/1744

missing_events = yield self.get_missing_events(
origin,
pdu.room_id,
earliest_events_ids=list(latest),
latest_events=[pdu],
limit=10,
min_depth=min_depth,
timeout=10000,
)

# We want to sort these by depth so we process them and
Expand Down
5 changes: 3 additions & 2 deletions synapse/federation/transport/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def claim_client_keys(self, destination, query_content, timeout):
@defer.inlineCallbacks
@log_function
def get_missing_events(self, destination, room_id, earliest_events,
latest_events, limit, min_depth):
latest_events, limit, min_depth, timeout):
path = PREFIX + "/get_missing_events/%s" % (room_id,)

content = yield self.client.post_json(
Expand All @@ -397,7 +397,8 @@ def get_missing_events(self, destination, room_id, earliest_events,
"min_depth": int(min_depth),
"earliest_events": earliest_events,
"latest_events": latest_events,
}
},
timeout=timeout,
)

defer.returnValue(content)

0 comments on commit 5175094

Please sign in to comment.