From a5096a88b19ec2a295fc233bc62a2f956e04e163 Mon Sep 17 00:00:00 2001 From: Teodora Sechkova Date: Thu, 7 Oct 2021 15:13:45 +0300 Subject: [PATCH] ngclient: remove sleep_before_round The purpose of this config was to ensure blocking inside the download loop and releasing CPU resources. To our best knowledge the network stack currently used in RequestsFetcher will always block inside the loop and the issue cannot be reproduced. 'chunk_size' and 'socket_timeout' are currently the settings provided by RequestsFetcher to tweak CPU usage and download granularity. Signed-off-by: Teodora Sechkova --- tuf/ngclient/_internal/requests_fetcher.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tuf/ngclient/_internal/requests_fetcher.py b/tuf/ngclient/_internal/requests_fetcher.py index 60f293e8..c2904164 100644 --- a/tuf/ngclient/_internal/requests_fetcher.py +++ b/tuf/ngclient/_internal/requests_fetcher.py @@ -6,8 +6,7 @@ """ import logging -import time -from typing import Dict, Iterator, Optional +from typing import Dict, Iterator from urllib import parse # Imports @@ -51,7 +50,6 @@ def __init__(self) -> None: # Default settings self.socket_timeout: int = 4 # seconds self.chunk_size: int = 400000 # bytes - self.sleep_before_round: Optional[int] = None def fetch(self, url: str) -> Iterator[bytes]: """Fetches the contents of HTTP/HTTPS url from a remote server @@ -104,11 +102,7 @@ def _chunks(self, response: "requests.Response") -> Iterator[bytes]: # We download a fixed chunk of data in every round. This is # so that we can defend against slow retrieval attacks. # Furthermore, we do not wish to download an extremely - # large file in one shot. Before beginning the round, sleep - # (if set) for a short amount of time so that the CPU is not - # hogged in the while loop. - if self.sleep_before_round: - time.sleep(self.sleep_before_round) + # large file in one shot. # NOTE: This may not handle some servers adding a # Content-Encoding header, which may cause urllib3 to