Commit 3ada47f8 authored by Julien Muchembled's avatar Julien Muchembled

registry: increase/fix timeouts for requests done by getBootstrapPeer/topology RPC

parent 58204ee8
...@@ -355,10 +355,11 @@ class RegistryServer(object): ...@@ -355,10 +355,11 @@ class RegistryServer(object):
with self.lock: with self.lock:
address = utils.ipFromBin(self.network + peer), tunnel.PORT address = utils.ipFromBin(self.network + peer), tunnel.PORT
self.sock.sendto('\2', address) self.sock.sendto('\2', address)
start = time.time() s = self.sock,
timeout = 1 timeout = 3
end = timeout + time.time()
# Loop because there may be answers from previous requests. # Loop because there may be answers from previous requests.
while select.select([self.sock], [], [], timeout)[0]: while select.select(s, (), (), timeout)[0]:
msg = self.sock.recv(1<<16) msg = self.sock.recv(1<<16)
if msg[0] == '\1': if msg[0] == '\1':
try: try:
...@@ -367,7 +368,7 @@ class RegistryServer(object): ...@@ -367,7 +368,7 @@ class RegistryServer(object):
continue continue
if msg.split()[0] == peer: if msg.split()[0] == peer:
break break
timeout = max(0, time.time() - start) timeout = max(0, end - time.time())
else: else:
logging.info("Timeout while querying [%s]:%u", *address) logging.info("Timeout while querying [%s]:%u", *address)
return return
...@@ -419,9 +420,9 @@ class RegistryServer(object): ...@@ -419,9 +420,9 @@ class RegistryServer(object):
peers = deque(('%u/%u' % (int(self.prefix, 2), len(self.prefix)),)) peers = deque(('%u/%u' % (int(self.prefix, 2), len(self.prefix)),))
cookie = hex(random.randint(0, 1<<32))[2:] cookie = hex(random.randint(0, 1<<32))[2:]
graph = dict.fromkeys(peers) graph = dict.fromkeys(peers)
s = self.sock,
while True: while True:
r, w, _ = select.select([self.sock], r, w, _ = select.select(s, s if peers else (), (), 3)
[self.sock] if peers else [], [], 1)
if r: if r:
answer = self.sock.recv(1<<16) answer = self.sock.recv(1<<16)
if answer[0] == '\xfe': if answer[0] == '\xfe':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment