Default timeout stopped working starting from urllib3 2.0.0

Bug #2018567 reported by Vsevolod Fedorov
36
This bug affects 6 people
Affects Status Importance Assigned to Milestone
Python Jenkins
In Progress
Undecided
Unassigned

Bug Description

urllib3 library does not use socket._GLOBAL_DEFAULT_TIMEOUT as it's default value starting from version 2.0.0. Now it uses it's own value. So, when timeout passed to it is compared to default one, it fails with the following trace:

 File "/usr/local/lib/python3.8/site-packages/jenkins/__init__.py", line 822, in get_info
    return json.loads(self.jenkins_open(
  File "/usr/local/lib/python3.8/site-packages/jenkins/__init__.py", line 560, in jenkins_open
    return self.jenkins_request(req, add_crumb, resolve_auth).text
  File "/usr/local/lib/python3.8/site-packages/jenkins/__init__.py", line 576, in jenkins_request
    self.maybe_add_crumb(req)
  File "/usr/local/lib/python3.8/site-packages/jenkins/__init__.py", line 373, in maybe_add_crumb
    response = self.jenkins_open(requests.Request(
  File "/usr/local/lib/python3.8/site-packages/jenkins/__init__.py", line 560, in jenkins_open
    return self.jenkins_request(req, add_crumb, resolve_auth).text
  File "/usr/local/lib/python3.8/site-packages/jenkins/__init__.py", line 579, in jenkins_request
    self._request(req))
  File "/usr/local/lib/python3.8/site-packages/jenkins/__init__.py", line 553, in _request
    return self._session.send(r, **_settings)
  File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 483, in send
    timeout = TimeoutSauce(connect=timeout, read=timeout)
  File "/usr/local/lib/python3.8/site-packages/urllib3/util/timeout.py", line 119, in __init__
    self._connect = self._validate_timeout(connect, "connect")
  File "/usr/local/lib/python3.8/site-packages/urllib3/util/timeout.py", line 156, in _validate_timeout
    raise ValueError(
ValueError: Timeout value connect was <object object at 0x7f960143b240>, but it must be an int, float or None.

Revision history for this message
Vsevolod Fedorov (vsevolod-fedorov-nx) wrote :

This is one possible solution.

Revision history for this message
Anil Shashikumar Belur (askb23) wrote :

I think we are hitting the same issue with our jobs:

21:45:19 ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
21:45:19 botocore 1.29.129 requires urllib3<1.27,>=1.25.4, but you have urllib3 2.0.2 which is incompatible.
21:45:19 python-jenkins 1.8.0 requires setuptools<66, but you have setuptools 67.7.2 which is incompatible.

21:20:58 During handling of the above exception, another exception occurred:
21:20:58
21:20:58 File "/tmp/venv-khYE/lib/python3.10/site-packages/jenkins/__init__.py", line 576, in jenkins_request
21:20:58 self.maybe_add_crumb(req)
21:20:58 File "/tmp/venv-khYE/lib/python3.10/site-packages/jenkins/__init__.py", line 373, in maybe_add_crumb
21:20:58 response = self.jenkins_open(requests.Request(
21:20:58 File "/tmp/venv-khYE/lib/python3.10/site-packages/jenkins/__init__.py", line 560, in jenkins_open
21:20:58 return self.jenkins_request(req, add_crumb, resolve_auth).text
21:20:58 File "/tmp/venv-khYE/lib/python3.10/site-packages/jenkins/__init__.py", line 579, in jenkins_request
21:20:58 self._request(req))
21:20:58 File "/tmp/venv-khYE/lib/python3.10/site-packages/jenkins/__init__.py", line 553, in _request
21:20:58 return self._session.send(r, **_settings)
21:20:58 File "/tmp/venv-khYE/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
21:20:58 r = adapter.send(request, **kwargs)
21:20:58 File "/tmp/venv-khYE/lib/python3.10/site-packages/requests/adapters.py", line 483, in send
21:20:58 timeout = TimeoutSauce(connect=timeout, read=timeout)
21:20:58 File "/tmp/venv-khYE/lib/python3.10/site-packages/urllib3/util/timeout.py", line 119, in __init__
21:20:58 self._connect = self._validate_timeout(connect, "connect")
21:20:58 File "/tmp/venv-khYE/lib/python3.10/site-packages/urllib3/util/timeout.py", line 156, in _validate_timeout
21:20:58 raise ValueError(
21:20:58 ValueError: Timeout value connect was <object object at 0x7fe57a4948a0>, but it must be an int, float or None.
21:20:58 Traceback (most recent call last):
21:20:58
21:20:58 During handling of the above exception, another exception occurred:

Revision history for this message
Vsevolod Fedorov (vsevolod-fedorov-nx) wrote (last edit ):

As a temporary workaround, you can fix urllib3 version in your requirements.txt file, like:
urllib3<2.0.0

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-jenkins (master)

Fix proposed to branch: master
Review: https://review.opendev.org/c/jjb/python-jenkins/+/882757

Changed in python-jenkins:
status: New → In Progress
Revision history for this message
Ken Dreyer (Red Hat) (kdreyer-redhat) wrote :

Vsevolod I've submitted your patch with modifications at https://review.opendev.org/c/jjb/python-jenkins/+/882757

Revision history for this message
Martin Wallgren (ub71-martin-b69y) wrote :

Another workaround if you don't want to pin urllib3 is to set your own timeout in the Jenkins constructor

            jenkins.Jenkins(
                jenkins_url,
                username,
                password,
                timeout=60,
            )

Revision history for this message
Bogdan Sucheana (bsucheana) wrote :

Another solution is to add in your config file (e.g. jenkins_jobs.ini) the timeout property, down in the [jenkins] section, like so:

[...]

[jenkins]
user=youruser
password=yourpassword
url=http://localhost:8080/
timeout=60
query_plugins_info=False
##### This is deprecated, use job_builder section instead
#ignore_cache=True

[...]

I'm using Python 3.11.4, so hopefully this will get fixed once the above patch is being merged.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.