From 544d882fef3de14e4e257fcf71376add1dce4238 Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Feb 10 2020 13:35:38 +0000 Subject: Add timeout to all requests calls Use the net_timeout value to limit all network communication. It should apply to the initial connection to the server and then to any pause in sending the data. Rather than possibly waiting forever, let's raise a clear exception. JIRA: COMPOSE-4102 --- diff --git a/server/odcs/server/auth.py b/server/odcs/server/auth.py index f9dadce..3639b7a 100644 --- a/server/odcs/server/auth.py +++ b/server/odcs/server/auth.py @@ -202,7 +202,9 @@ def get_user_info(token): headers = { 'authorization': 'Bearer {0}'.format(token) } - r = requests.get(conf.auth_openidc_userinfo_uri, headers=headers) + r = requests.get( + conf.auth_openidc_userinfo_uri, headers=headers, timeout=conf.net_timeout + ) if r.status_code != 200: # In Fedora, the manually created service tokens can't be used with the UserInfo # endpoint. We treat this as an empty response - and hence an empty group list. An empty diff --git a/server/odcs/server/mergerepo.py b/server/odcs/server/mergerepo.py index a6e0fa7..04f9202 100644 --- a/server/odcs/server/mergerepo.py +++ b/server/odcs/server/mergerepo.py @@ -50,7 +50,7 @@ class MergeRepo(object): :return: content of downloaded file. """ log.info("%r: Downloading %s", self.compose, url) - r = requests.get(url) + r = requests.get(url, timeout=conf.net_timeout) r.raise_for_status() filename = os.path.basename(url) diff --git a/server/odcs/server/pulp.py b/server/odcs/server/pulp.py index 26f2902..fefce90 100644 --- a/server/odcs/server/pulp.py +++ b/server/odcs/server/pulp.py @@ -26,6 +26,7 @@ import copy import json import requests +from odcs.server import conf from odcs.server.mergerepo import MergeRepo from odcs.server.utils import retry @@ -46,7 +47,9 @@ class Pulp(object): r = requests.post( '{0}{1}'.format(self.rest_api_root, endpoint.lstrip('/')), query_data, - auth=(self.username, self.password)) + auth=(self.username, self.password), + timeout=conf.net_timeout, + ) r.raise_for_status() return r.json() diff --git a/server/odcs/server/pungi_compose.py b/server/odcs/server/pungi_compose.py index 524992a..2433155 100644 --- a/server/odcs/server/pungi_compose.py +++ b/server/odcs/server/pungi_compose.py @@ -25,6 +25,8 @@ import os import requests import productmd.common +from odcs.server import conf + class PungiCompose(object): """Represents 3rd party Pungi Compose""" @@ -47,7 +49,7 @@ class PungiCompose(object): """ Fetches the json file represented by `url`. """ - r = requests.get(url) + r = requests.get(url, timeout=conf.net_timeout) r.raise_for_status() return r.json()