From 105a7c0ea67a935274e0565aeb93833287757446 Mon Sep 17 00:00:00 2001 From: Kenny Lee Sin Cheong Date: Fri, 7 Sep 2018 13:40:20 -0400 Subject: [PATCH] Worker started flag --- util/ipresolver/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/util/ipresolver/__init__.py b/util/ipresolver/__init__.py index c55ca2d11..77d97a9cb 100644 --- a/util/ipresolver/__init__.py +++ b/util/ipresolver/__init__.py @@ -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,11 +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.is_alive() and \ + not self._worker_started: 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)