aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucio Sauer <watermanpaint@posteo.net>2024-04-30 23:28:51 +0200
committerArthur Zamarin <arthurzam@gentoo.org>2024-05-08 19:23:21 +0300
commit298deaf274ff1fdf61de021ee8df060c3ca52033 (patch)
tree1e7ce05f05eed0416e4e7ca5f0603cd9f6710078
parentpyproject: bump snakeoil to restore compat with >=python-3.11.9 (diff)
downloadpkgcheck-298deaf274ff1fdf61de021ee8df060c3ca52033.tar.gz
pkgcheck-298deaf274ff1fdf61de021ee8df060c3ca52033.tar.bz2
pkgcheck-298deaf274ff1fdf61de021ee8df060c3ca52033.zip
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@posteo.net> Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r--src/pkgcheck/addons/__init__.py12
-rw-r--r--src/pkgcheck/addons/net.py7
-rw-r--r--src/pkgcheck/checks/__init__.py2
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