diff --git a/aiohttp/connector.py b/aiohttp/connector.py index f51641c4046..4205affaeae 100644 --- a/aiohttp/connector.py +++ b/aiohttp/connector.py @@ -7,7 +7,7 @@ from contextlib import suppress from hashlib import md5, sha1, sha256 from http.cookies import SimpleCookie -from itertools import cycle, islice +from random import shuffle from time import monotonic from types import MappingProxyType @@ -547,7 +547,6 @@ class _DNSCacheTable: def __init__(self, ttl=None): self._addrs = {} - self._addrs_rr = {} self._timestamps = {} self._ttl = ttl @@ -560,28 +559,24 @@ def addrs(self): def add(self, host, addrs): self._addrs[host] = addrs - self._addrs_rr[host] = cycle(addrs) if self._ttl: self._timestamps[host] = monotonic() def remove(self, host): self._addrs.pop(host, None) - self._addrs_rr.pop(host, None) if self._ttl: self._timestamps.pop(host, None) def clear(self): self._addrs.clear() - self._addrs_rr.clear() self._timestamps.clear() def next_addrs(self, host): - # Return an iterator that will get at maximum as many addrs - # there are for the specific host starting from the last - # not itereated addr. - return islice(self._addrs_rr[host], len(self._addrs[host])) + addrs = self._addrs[host].copy() + shuffle(addrs) + return addrs def expired(self, host): if self._ttl is None: