From 7e3512cbf27bb4e3922763c3a353562040b79e2e Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Mon, 1 Oct 2018 01:14:47 -0300 Subject: [PATCH 1/2] retry on protocol level --- lbrynet/dht/protocol.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lbrynet/dht/protocol.py b/lbrynet/dht/protocol.py index 638d975ef..448006688 100644 --- a/lbrynet/dht/protocol.py +++ b/lbrynet/dht/protocol.py @@ -118,7 +118,20 @@ class KademliaProtocol(protocol.DatagramProtocol): return args return args + ({b'protocolVersion': self._protocolVersion},) + @defer.inlineCallbacks def sendRPC(self, contact, method, args): + while True: + try: + response = yield self._sendRPC(contact, method, args) + return response + except TimeoutError: + if contact.contact_is_good: + log.debug("RETRY %s ON %s", method, contact) + continue + else: + raise + + def _sendRPC(self, contact, method, args): """ Sends an RPC to the specified contact @@ -153,11 +166,12 @@ class KademliaProtocol(protocol.DatagramProtocol): df = defer.Deferred() def _remove_contact(failure): # remove the contact from the routing table and track the failure + contact.update_last_failed() try: - self._node.removeContact(contact) + if not contact.contact_is_good: + self._node.removeContact(contact) except (ValueError, IndexError): pass - contact.update_last_failed() return failure def _update_contact(result): # refresh the contact in the routing table From db898307b5a75a6e0c386930c516e708d9019d2e Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Mon, 8 Oct 2018 16:51:30 -0300 Subject: [PATCH 2/2] obey the rpcAttempts constant on retries --- lbrynet/dht/protocol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lbrynet/dht/protocol.py b/lbrynet/dht/protocol.py index 448006688..18d55977a 100644 --- a/lbrynet/dht/protocol.py +++ b/lbrynet/dht/protocol.py @@ -120,7 +120,7 @@ class KademliaProtocol(protocol.DatagramProtocol): @defer.inlineCallbacks def sendRPC(self, contact, method, args): - while True: + for _ in range(constants.rpcAttempts): try: response = yield self._sendRPC(contact, method, args) return response