Fix handling of socket retries
Simply trying to re-fetch the value was insufficient. A full-retry by
also re-sending the request was required.
@@ -40,17 +40,18 @@ def send(ip, port, packet, timeout=2): # pragma: no cover
sock = socket.socket(address_family, socket.SOCK_DGRAM)
sock.settimeout(timeout)
+ for num_retry in range(RETRIES):
+ try:
if LOG.isEnabledFor(logging.DEBUG):
hexdump = visible_octets(packet)
- LOG.debug('Sending packet to %s:%s\n%s', ip, port, hexdump)
-
+ LOG.debug('Sending packet to %s:%s (attempt %d/%d)\n%s',
+ ip, port, (num_retry+1), RETRIES, hexdump)
sock.sendto(packet, (ip, port))
- for _ in range(RETRIES):
- try:
response = sock.recv(8192)
break
except socket.timeout:
- LOG.debug('Timeout') # TODO add detail
+ LOG.debug('Timeout during attempt #%d',
+ (num_retry+1)) # TODO add detail
continue
else:
raise Timeout("Max of %d retries reached" % RETRIES)
