commit:     298deaf274ff1fdf61de021ee8df060c3ca52033
Author:     Lucio Sauer <watermanpaint <AT> posteo <DOT> net>
AuthorDate: Tue Apr 30 21:28:51 2024 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Wed May  8 16:23:21 2024 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=298deaf2

fix crash when performing --timeout 0 call to ftp:// site

e.g.
pkgcheck scan --net -c HomepageUrlCheck --timeout 0 app-admin/chrootuid
at checkout 127160ac611d39cc6bb2ca21fcf99a086fe2b176

Python's ftplib raises a ValueError with timeout=0. Use timeout=None to
put the underlying socket in blocking mode. See
https://docs.python.org/3/library/socket.html#socket.socket.settimeout
for legal timeout values.

Signed-off-by: Lucio Sauer <watermanpaint <AT> posteo.net>
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/pkgcheck/addons/__init__.py | 12 +++++++++++-
 src/pkgcheck/addons/net.py      |  7 +------
 src/pkgcheck/checks/__init__.py |  2 +-
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/pkgcheck/addons/__init__.py b/src/pkgcheck/addons/__init__.py
index 56678669..c621c53b 100644
--- a/src/pkgcheck/addons/__init__.py
+++ b/src/pkgcheck/addons/__init__.py
@@ -274,6 +274,16 @@ class UseAddon(base.Addon):
 class NetAddon(base.Addon):
     """Addon supporting network functionality."""
 
+    def __init__(self, *args):
+        super().__init__(*args)
+
+        if self.options.timeout == 0:
+            # set timeout to 0 to never timeout
+            self.timeout = None
+        else:
+            # default to timing out connections after 5 seconds
+            self.timeout = self.options.timeout if self.options.timeout is not 
None else 5
+
     @classmethod
     def mangle_argparser(cls, parser):
         group = parser.add_argument_group("network")
@@ -291,7 +301,7 @@ class NetAddon(base.Addon):
 
             return Session(
                 concurrent=self.options.tasks,
-                timeout=self.options.timeout,
+                timeout=self.timeout,
                 user_agent=self.options.user_agent,
             )
         except ImportError as e:

diff --git a/src/pkgcheck/addons/net.py b/src/pkgcheck/addons/net.py
index 782d74d1..91101282 100644
--- a/src/pkgcheck/addons/net.py
+++ b/src/pkgcheck/addons/net.py
@@ -18,12 +18,7 @@ class Session(requests.Session):
 
     def __init__(self, concurrent=None, timeout=None, user_agent=None):
         super().__init__()
-        if timeout == 0:
-            # set timeout to 0 to never timeout
-            self.timeout = None
-        else:
-            # default to timing out connections after 5 seconds
-            self.timeout = timeout if timeout is not None else 5
+        self.timeout = timeout
 
         # block when urllib3 connection pool is full
         concurrent = concurrent if concurrent is not None else os.cpu_count() 
* 5

diff --git a/src/pkgcheck/checks/__init__.py b/src/pkgcheck/checks/__init__.py
index b5caa244..556f720e 100644
--- a/src/pkgcheck/checks/__init__.py
+++ b/src/pkgcheck/checks/__init__.py
@@ -127,7 +127,7 @@ class NetworkCheck(AsyncCheck, OptionalCheck):
         super().__init__(*args, **kwargs)
         if not self.options.net:
             raise SkipCheck(self, "network checks not enabled")
-        self.timeout = self.options.timeout
+        self.timeout = net_addon.timeout
         self.session = net_addon.session
 
 

Reply via email to