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 #991 from matrix-org/erikj/retry_make
Browse files Browse the repository at this point in the history
Retry joining via other servers if first one failed. Fix some other bugs.
  • Loading branch information
erikjohnston authored Aug 5, 2016
2 parents 6bf6bc1 + 5f36018 commit f5deaff
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ def get_pdu(self, destinations, event_id, outlier=False, timeout=None):
# TODO: Rate limit the number of times we try and get the same event.

if self._get_pdu_cache:
e = self._get_pdu_cache.get(event_id)
if e:
defer.returnValue(e)
ev = self._get_pdu_cache.get(event_id)
if ev:
defer.returnValue(ev)

pdu = None
for destination in destinations:
Expand Down Expand Up @@ -269,7 +269,7 @@ def get_pdu(self, destinations, event_id, outlier=False, timeout=None):

break

except SynapseError:
except SynapseError as e:
logger.info(
"Failed to get PDU %s from %s because %s",
event_id, destination, e,
Expand Down Expand Up @@ -336,8 +336,10 @@ def get_state_for_room(self, destination, room_id, event_id):
ev.event_id: ev for ev in fetched_events
}

pdus = [event_map[e_id] for e_id in state_event_ids]
auth_chain = [event_map[e_id] for e_id in auth_event_ids]
pdus = [event_map[e_id] for e_id in state_event_ids if e_id in event_map]
auth_chain = [
event_map[e_id] for e_id in auth_event_ids if e_id in event_map
]

auth_chain.sort(key=lambda e: e.depth)

Expand Down Expand Up @@ -523,14 +525,19 @@ def make_membership_event(self, destinations, room_id, user_id, membership,
(destination, self.event_from_pdu_json(pdu_dict))
)
break
except CodeMessageException:
raise
except CodeMessageException as e:
if not 500 <= e.code < 600:
raise
else:
logger.warn(
"Failed to make_%s via %s: %s",
membership, destination, e.message
)
except Exception as e:
logger.warn(
"Failed to make_%s via %s: %s",
membership, destination, e.message
)
raise

raise RuntimeError("Failed to send to any server.")

Expand Down Expand Up @@ -602,8 +609,14 @@ def send_join(self, destinations, pdu):
"auth_chain": signed_auth,
"origin": destination,
})
except CodeMessageException:
raise
except CodeMessageException as e:
if not 500 <= e.code < 600:
raise
else:
logger.exception(
"Failed to send_join via %s: %s",
destination, e.message
)
except Exception as e:
logger.exception(
"Failed to send_join via %s: %s",
Expand Down

0 comments on commit f5deaff

Please sign in to comment.