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

Retry joining via other servers if first one failed. Fix some other bugs. #991

Merged
merged 2 commits into from
Aug 5, 2016
Merged
Changes from all 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
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