From: Michael Tremer Date: Thu, 7 Mar 2024 12:24:18 +0000 (+0000) Subject: importer: Timeout if fetching a Geofeed takes longer than 5 seconds X-Git-Tag: 0.9.18~94 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=776226b608ded5b36a951676348a0c83a19463ef;p=location%2Flibloc.git importer: Timeout if fetching a Geofeed takes longer than 5 seconds Signed-off-by: Michael Tremer --- diff --git a/src/python/location/downloader.py b/src/python/location/downloader.py index 4e9e184..3dffbc7 100644 --- a/src/python/location/downloader.py +++ b/src/python/location/downloader.py @@ -209,7 +209,7 @@ class Downloader(object): return True - def retrieve(self, url, **kwargs): + def retrieve(self, url, timeout=None, **kwargs): """ This method will fetch the content at the given URL and will return a file-object to a temporary file. @@ -223,7 +223,7 @@ class Downloader(object): req = self._make_request(url, **kwargs) # Send request - res = self._send_request(req) + res = self._send_request(req, timeout=timeout) # Write the payload to the temporary file with res as f: diff --git a/src/scripts/location-importer.in b/src/scripts/location-importer.in index 39bfcfc..2de49fb 100644 --- a/src/scripts/location-importer.in +++ b/src/scripts/location-importer.in @@ -1710,7 +1710,12 @@ class CLI(object): try: # Send the request f = await asyncio.to_thread( - self.downloader.retrieve, geofeed.url, + self.downloader.retrieve, + + # Fetch the feed by its URL + geofeed.url, + + # Send some extra headers headers={ "User-Agent" : "location/%s" % location.__version__, @@ -1719,7 +1724,7 @@ class CLI(object): }, # Don't wait longer than 10 seconds for a response - #timeout=10, + timeout=10, ) # Remove any previous data