]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
importer: Timeout if fetching a Geofeed takes longer than 5 seconds
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 7 Mar 2024 12:24:18 +0000 (12:24 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 7 Mar 2024 12:24:18 +0000 (12:24 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/location/downloader.py
src/scripts/location-importer.in

index 4e9e1847e234b5ddec7edc40a51c084db8bf5b3a..3dffbc7743a0cd2c609eb2764a4754ee04ac6956 100644 (file)
@@ -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:
index 39bfcfc2210b5702fd49cee7b939e9c62fe9fcdb..2de49fbc2ac28c3ca19c2fc2ff1760d0525619c2 100644 (file)
@@ -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