Merge pull request #3244 from kleesc/IPResolver-fix

Fix: Should not break from ipresolver thread
This commit is contained in:
Joseph Schorr 2018-09-07 15:48:08 -04:00 committed by GitHub
commit b19443c4e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -84,6 +84,7 @@ class IPResolver(IPResolverInterface):
self.app = app
self.geoip_db = geoip2.database.Reader('util/ipresolver/GeoLite2-Country.mmdb')
self._worker = _UpdateIPRange(_UPDATE_INTERVAL)
self._worker_started = False
@ttl_cache(maxsize=100, ttl=600)
def is_ip_possible_threat(self, ip_address):
@ -129,8 +130,14 @@ class IPResolver(IPResolverInterface):
return location_function(ip_address)
def _get_location_function(self):
if not self.app.config.get('TESTING', False) and not self._worker.is_alive():
if (not self.app.config.get('TESTING', False) and not self._worker_started and
not self._worker.is_alive()):
try:
self._worker.start()
self._worker_started = True
except:
logger.exception('Got exception try to start ip resolver thread')
try:
cache = CACHE
sync_token = cache.get('sync_token', None)
@ -210,7 +217,7 @@ class _UpdateIPRange(Thread):
except:
logger.exception('Failed trying to update aws ip range')
time.sleep(_FAILED_UPDATE_RETRY_SECS)
break
continue
sync_token = aws_ip_range_json['syncToken']
all_amazon, regions = IPResolver._parse_amazon_ranges(aws_ip_range_json)