Skip to content

Commit

Permalink
increase default network timeout (#2542)
Browse files Browse the repository at this point in the history
* Increase default network timeout
* trying to defend against slow retrieval attacks in a generic library is impossible
but too low timeouts mean failures in high latency systems (like tests running
on CI).

Signed-off-by: E3E <ntanzill@purdue.edu>
  • Loading branch information
NicholasTanz committed Feb 1, 2024
1 parent 3f896c0 commit af4beb1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions tuf/ngclient/_internal/requests_fetcher.py
Expand Up @@ -29,12 +29,13 @@ class RequestsFetcher(FetcherInterface):
Attributes:
socket_timeout: Timeout in seconds, used for both initial connection
delay and the maximum delay between bytes received. Default is
4 seconds.
delay and the maximum delay between bytes received.
chunk_size: Chunk size in bytes used when downloading.
"""

def __init__(self) -> None:
def __init__(
self, socket_timeout: int = 30, chunk_size: int = 400000
) -> None:
# http://docs.python-requests.org/en/master/user/advanced/#session-objects:
#
# "The Session object allows you to persist certain parameters across
Expand All @@ -52,8 +53,8 @@ def __init__(self) -> None:
self._sessions: Dict[Tuple[str, str], requests.Session] = {}

# Default settings
self.socket_timeout: int = 4 # seconds
self.chunk_size: int = 400000 # bytes
self.socket_timeout: int = socket_timeout # seconds
self.chunk_size: int = chunk_size # bytes

def _fetch(self, url: str) -> Iterator[bytes]:
"""Fetch the contents of HTTP/HTTPS url from a remote server.
Expand Down

0 comments on commit af4beb1

Please sign in to comment.