diff --git a/shadowsocks/lru_cache.py b/shadowsocks/lru_cache.py index 401f19b..e67fdff 100644 --- a/shadowsocks/lru_cache.py +++ b/shadowsocks/lru_cache.py @@ -88,12 +88,12 @@ class LRUCache(collections.MutableMapping): self.close_callback(value) self._closed_values.add(value) for key in self._time_to_keys[least]: - self._last_visits.popleft() if key in self._store: if now - self._keys_to_last_time[key] > self.timeout: del self._store[key] del self._keys_to_last_time[key] c += 1 + self._last_visits.popleft() del self._time_to_keys[least] if c: self._closed_values.clear() diff --git a/shadowsocks/udprelay.py b/shadowsocks/udprelay.py index d3696d9..b4fcae3 100644 --- a/shadowsocks/udprelay.py +++ b/shadowsocks/udprelay.py @@ -1293,6 +1293,7 @@ class UDPRelay(object): logging.info('closed UDP port %d', self._listen_port) before_sweep_size = len(self._sockets) self._cache.sweep() + self._dns_cache.sweep() if before_sweep_size != len(self._sockets): logging.debug('UDP port %5d sockets %d' % (self._listen_port, len(self._sockets))) self._client_fd_to_server_addr.sweep()