Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #211 - Fix RIS HTTP timeouts #212

Merged
merged 2 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dnas/dnas/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ class config:
# Base dir to save MRT files to
DL_DIR = os.path.join(DATA_DIR, "downloads/")

# Number of retires for downloading an MRT file
DL_RETIRES = 3

# Seconds between retires
DL_DELAY = 10

# Temporary directory to split MRT files into
SPLIT_DIR = "/tmp/" # Set to None to disable MRT splitting

Expand Down
30 changes: 24 additions & 6 deletions dnas/dnas/mrt_getter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import logging
import os
from time import sleep
from typing import Literal, Tuple, Union

import requests
Expand Down Expand Up @@ -183,13 +184,30 @@ def download_file(
logging.info(f"Downloading {url} to {filename}")
try:
"""
The default Accept-Encoding is gzip, which causes the server to
respond with a Content-Length which is not the full file
size. Replace this so we can later compare the file size:
When pulling files from RIPE RIS, there are occasional timeouts.
Retry a few times with a pause between attempts because this seems
to almost always be a transient error.
"""
req = requests.get(
url, headers={"Accept-Encoding": "*"}, stream=True
)
retries = cfg.DL_RETIRES
while retries > 0:
try:
"""
The default Accept-Encoding is gzip, which causes the server
to respond with a Content-Length which is not the full file
size. Replace this so we can later compare the file size:
"""
req = requests.get(
url, headers={"Accept-Encoding": "*"}, stream=True
)
retries = 0
except requests.exceptions.ReadTimeout as e:
retries -= 1
logging.info(
f"Request timeout connecting to HTTP server: {e}\n"
f"Remaining retires: {retries}\n"
f"Waiting {cfg.DL_DELAY} seconds..."
)
sleep(cfg.DL_DELAY)
except requests.exceptions.ConnectionError as e:
logging.info(f"Couldn't connect to HTTP server: {e}")
raise requests.exceptions.ConnectionError
Expand Down
14 changes: 7 additions & 7 deletions dnas/dnas/mrt_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ def from_json(self: "mrt_stats", json_str: str) -> None:
mrt_e = mrt_entry()
mrt_e.from_json(json_e)
self.bogon_origin_asns.append(mrt_e)
#else:
# else:
# self.bogon_origin_asns.append(mrt_entry())
# Breaks report generations -> remove if stable after commenting out

Expand All @@ -1268,7 +1268,7 @@ def from_json(self: "mrt_stats", json_str: str) -> None:
mrt_e = mrt_entry()
mrt_e.from_json(json_e)
self.bogon_prefixes.append(mrt_e)
#else:
# else:
# self.bogon_prefixes.append(mrt_entry())
# Breaks report generations -> remove if stable after commenting out

Expand All @@ -1278,7 +1278,7 @@ def from_json(self: "mrt_stats", json_str: str) -> None:
mrt_e = mrt_entry()
mrt_e.from_json(json_e)
self.highest_med_prefixes.append(mrt_e)
#else:
# else:
# self.highest_med_prefixes.append(mrt_entry())
# Breaks report generations -> remove if stable after commenting out

Expand All @@ -1288,7 +1288,7 @@ def from_json(self: "mrt_stats", json_str: str) -> None:
mrt_e = mrt_entry()
mrt_e.from_json(json_e)
self.invalid_len.append(mrt_e)
#else:
# else:
# self.invalid_len.append(mrt_entry())
# Breaks report generations -> remove if stable after commenting out

Expand Down Expand Up @@ -1316,7 +1316,7 @@ def from_json(self: "mrt_stats", json_str: str) -> None:
mrt_e = mrt_entry()
mrt_e.from_json(json_e)
self.most_bogon_asns.append(mrt_e)
#else:
# else:
# self.most_bogon_asns.append(mrt_entry())
# Breaks report generations -> remove if stable after commenting out

Expand Down Expand Up @@ -1368,7 +1368,7 @@ def from_json(self: "mrt_stats", json_str: str) -> None:
mrt_e = mrt_entry()
mrt_e.from_json(json_e)
self.most_unknown_attrs.append(mrt_e)
#else:
# else:
# self.most_unknown_attrs.append(mrt_entry())
# Breaks report generations -> remove if stable after commenting out

Expand All @@ -1378,7 +1378,7 @@ def from_json(self: "mrt_stats", json_str: str) -> None:
mrt_e = mrt_entry()
mrt_e.from_json(json_e)
self.most_unreg_origins.append(mrt_e)
#else:
# else:
# self.most_unreg_origins.append(mrt_entry())
# Breaks report generations -> remove if stable after commenting out

Expand Down