diff --git a/synapse/crypto/keyring.py b/synapse/crypto/keyring.py index eb94cd5b75..54a9c056af 100644 --- a/synapse/crypto/keyring.py +++ b/synapse/crypto/keyring.py @@ -243,14 +243,17 @@ class Keyring(object): type(e).__name__, str(e.message), ) - results = yield defer.gatherResults([ - get_key(p_name, p_keys) - for p_name, p_keys in self.perspective_servers.items() - ]) + results = yield defer.gatherResults( + [ + get_key(p_name, p_keys) + for p_name, p_keys in self.perspective_servers.items() + ], + consumeErrors=True, + ).addErrback(unwrapFirstError) union_of_keys = {} for result in results: - for server_name, keys in results.items(): + for server_name, keys in result.items(): union_of_keys.setdefault(server_name, {}).update(keys) defer.returnValue(union_of_keys) diff --git a/synapse/federation/federation_base.py b/synapse/federation/federation_base.py index 407e0f815c..dbec215c97 100644 --- a/synapse/federation/federation_base.py +++ b/synapse/federation/federation_base.py @@ -53,47 +53,50 @@ class FederationBase(object): signed_pdus = [] - @defer.inlineCallbacks - def do(pdu): - try: - new_pdu = yield self._check_sigs_and_hash(pdu) + deferreds = self._check_sigs_and_hashes(pdus) + + def callback(pdu): + signed_pdus.append(pdu) + + def errback(failure, pdu): + failure.trap(SynapseError) + + # Check local db. + new_pdu = yield self.store.get_event( + pdu.event_id, + allow_rejected=True, + allow_none=True, + ) + if new_pdu: signed_pdus.append(new_pdu) - except SynapseError: - # FIXME: We should handle signature failures more gracefully. + return - # Check local db. - new_pdu = yield self.store.get_event( - pdu.event_id, - allow_rejected=True, - allow_none=True, - ) - if new_pdu: - signed_pdus.append(new_pdu) - return + # Check pdu.origin + if pdu.origin != origin: + try: + new_pdu = yield self.get_pdu( + destinations=[pdu.origin], + event_id=pdu.event_id, + outlier=outlier, + timeout=10000, + ) - # Check pdu.origin - if pdu.origin != origin: - try: - new_pdu = yield self.get_pdu( - destinations=[pdu.origin], - event_id=pdu.event_id, - outlier=outlier, - timeout=10000, - ) + if new_pdu: + signed_pdus.append(new_pdu) + return + except: + pass - if new_pdu: - signed_pdus.append(new_pdu) - return - except: - pass + logger.warn( + "Failed to find copy of %s with valid signature", + pdu.event_id, + ) - logger.warn( - "Failed to find copy of %s with valid signature", - pdu.event_id, - ) + for pdu, deferred in zip(pdus, deferreds): + deferred.addCallbacks(callback, errback, errbackArgs=[pdu]) yield defer.gatherResults( - [do(pdu) for pdu in pdus], + deferreds, consumeErrors=True ).addErrback(unwrapFirstError)