From 5c9feefa86791097bbd744c454fd636c73285298 Mon Sep 17 00:00:00 2001 From: JordiMForgeFlow Date: Wed, 28 Oct 2026 14:21:12 +0100 Subject: [PATCH] [IMP] webservice: do not override timeout The requests adapters set the timeout to None on every call, discarding the one given by the caller. A call to a peer that accepts the connection but never answers then holds the worker until the peer closes the socket, which in a cron can block every other scheduled action for as long as the worker time limit allows. The timeout now travels in kwargs like any other requests parameter. Callers that pass none keep the previous behaviour, as requests defaults to no timeout. --- webservice/components/request_adapter.py | 2 -- webservice/tests/test_oauth2.py | 3 ++- webservice/tests/test_webservice.py | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/webservice/components/request_adapter.py b/webservice/components/request_adapter.py index bd225654..050d6772 100644 --- a/webservice/components/request_adapter.py +++ b/webservice/components/request_adapter.py @@ -35,7 +35,6 @@ def _request(self, method, url=None, url_params=None, **kwargs): { "auth": self._get_auth(**kwargs), "headers": self._get_headers(**kwargs), - "timeout": None, } ) # pylint: disable=E8106 @@ -180,7 +179,6 @@ def _request(self, method, url=None, url_params=None, **kwargs): new_kwargs.update( { "headers": self._get_headers(**kwargs), - "timeout": None, } ) client = BackendApplicationClient(client_id=self.collection.oauth2_clientid) diff --git a/webservice/tests/test_oauth2.py b/webservice/tests/test_oauth2.py index 648faeac..74c2b7fd 100644 --- a/webservice/tests/test_oauth2.py +++ b/webservice/tests/test_oauth2.py @@ -73,10 +73,11 @@ def test_fetch_token(self): responses.add(responses.GET, f"{self.url}endpoint", body="OK") with mock_cursor(self.env.cr): - result = self.webservice.call("get", url=f"{self.url}endpoint") + result = self.webservice.call("get", url=f"{self.url}endpoint", timeout=10) self.webservice.invalidate_recordset() self.assertTrue("cool_token" in self.webservice.oauth2_token) self.assertEqual(result, b"OK") + self.assertEqual(responses.calls[-1].request.req_kwargs["timeout"], 10) @responses.activate def test_update_token(self): diff --git a/webservice/tests/test_webservice.py b/webservice/tests/test_webservice.py index 46d734bc..329b4b1f 100644 --- a/webservice/tests/test_webservice.py +++ b/webservice/tests/test_webservice.py @@ -190,7 +190,7 @@ def test_web_service_call_args(self): url = "https://custom.url" responses.add(responses.POST, url, body="{}") result = self.webservice.call( - "post", url=url, headers={"demo_header": "HEADER"} + "post", url=url, headers={"demo_header": "HEADER"}, timeout=10 ) self.assertEqual(result, b"{}") self.assertEqual(len(responses.calls), 1) @@ -198,6 +198,7 @@ def test_web_service_call_args(self): responses.calls[0].request.headers["Content-Type"], "application/xml" ) self.assertEqual(responses.calls[0].request.headers["demo_header"], "HEADER") + self.assertEqual(responses.calls[0].request.req_kwargs["timeout"], 10) url = self.url + "custom/path" self.webservice.url += "{endpoint}"