Timeout not correctly set inside requests session object

Bug #2012261 reported by Christian
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
etcd3gw
Fix Released
High
Unassigned

Bug Description

There is currently no timeout set in the requests session object, which means it will wait indefinitely and cause the process to hang if no response is received.
For more information, see https://pylint.readthedocs.io/en/latest/user_guide/messages/warning/missing-timeout.html.

Steps to reproduce this Bug:

$ cat >timeout1.py<<EOF
import etcd3gw
client = etcd3gw.Etcd3Client(timeout=1)
resp = client.session.post("https://httpbin.org/delay/10")
print(resp.status_code)
EOF

Expected behavior:

requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='httpbin.org', port=443): Read timed out. (read timeout=1)

Actual behavior:
$ python3 timeout1.py
200

The issue can be resolved utilizing functools - https://github.com/psf/requests/issues/2011#issuecomment-637156626.

These are my proposed changes in fixing the timeout issue.

diff --git a/etcd3gw/client.py b/etcd3gw/client.py
index 43690ce..63fb588 100644
--- a/etcd3gw/client.py
+++ b/etcd3gw/client.py
@@ -10,6 +10,7 @@
 # License for the specific language governing permissions and limitations
 # under the License.

+import functools
 import json
 import os
 import queue
@@ -57,7 +58,10 @@ class Etcd3Client(object):

         self.session = requests.Session()
         if timeout is not None:
- self.session.timeout = timeout
+ self.session.request = functools.partial(self.session.request, timeout=timeout)
+ else:
+ self.session.request = functools.partial(self.session.request, timeout=DEFAULT_TIMEOUT)
+
         if ca_cert is not None:
             self.session.verify = ca_cert
         if cert_cert is not None and cert_key is not None:

description: updated
information type: Public → Public Security
information type: Public Security → Public
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to etcd3gw (master)

Fix proposed to branch: master
Review: https://review.opendev.org/c/openstack/etcd3gw/+/908585

Changed in python-etcd3gw:
status: New → In Progress
Changed in python-etcd3gw:
importance: Undecided → High
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to etcd3gw (master)

Reviewed: https://review.opendev.org/c/openstack/etcd3gw/+/908585
Committed: https://opendev.org/openstack/etcd3gw/commit/04c7907854bdc66c85147f79058732ed4828e960
Submitter: "Zuul (22348)"
Branch: master

commit 04c7907854bdc66c85147f79058732ed4828e960
Author: Takashi Kajinami <email address hidden>
Date: Fri Feb 9 23:25:48 2024 +0900

    Apply timeout in each request call

    ... instead adding it to Session objects which does not at all work.

    Closes-Bug: #2012261
    Change-Id: Ibcf0e2707b9834c51aa3f32333d48f57ea3f04fa

Changed in python-etcd3gw:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/etcd3gw 2.4.0

This issue was fixed in the openstack/etcd3gw 2.4.0 release.

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

Other bug subscribers

Remote bug watches

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