Skip to content

Commit e43c6ab

Browse files
committed
add timeout to all requests
1 parent a2e5ec5 commit e43c6ab

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

modules/prometheus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def push_metrics(self):
112112
self.local.try_function(self.get_validator_status_metrics, args=[metrics])
113113
self.local.try_function(self.get_validator_validation_metrics, args=[metrics])
114114
self.local.try_function(self.get_node_stats_metrics, args=[metrics])
115-
requests.post(url, data='\n'.join(metrics).encode())
115+
requests.post(url, data='\n'.join(metrics).encode(), timeout=3)
116116

117117
def add_console_commands(self, console):
118118
...

mytoncore/mytoncore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ def send_boc_toncenter(self, file_path: str):
12501250
url = self.local.db.get("duplicateApiUrl", default_url)
12511251
if url == None:
12521252
return False
1253-
result = requests.post(url=url, json=data)
1253+
result = requests.post(url=url, json=data, timeout=3)
12541254
if result.status_code != 200:
12551255
self.local.add_log(f'Failed to send boc to toncenter: {result.content}', 'info')
12561256
return False

mytoninstaller/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ def CreateLocalConfig(local, initBlock, localConfigPath=defaultLocalConfigPath):
112112
def get_own_ip():
113113
pat = re.compile(r"^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$")
114114
requests.packages.urllib3.util.connection.HAS_IPV6 = False
115-
ip = requests.get("https://ifconfig.me/ip").text
115+
ip = requests.get("https://ifconfig.me/ip", timeout=3).text
116116
if not pat.fullmatch(ip):
117-
ip = requests.get("https://ipinfo.io/ip").text
117+
ip = requests.get("https://ipinfo.io/ip", timeout=3).text
118118
if not pat.fullmatch(ip):
119119
raise Exception('Cannot get own IP address')
120120
return ip

mytoninstaller/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def DownloadDump(local):
254254
url = "https://dump.ton.org/dumps/latest"
255255
if is_testnet(local):
256256
url += '_testnet'
257-
dumpSize = requests.get(url + ".tar.size.archive.txt").text
257+
dumpSize = requests.get(url + ".tar.size.archive.txt", timeout=3).text
258258
print("dumpSize:", dumpSize)
259259
needSpace = int(dumpSize) * 3
260260
diskSpace = psutil.disk_usage("/var")

scripts/install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def get_archive_ttl_message(answers: dict):
1818
url = f'https://toncenter.com/api/v2/getBlockHeader?workchain=-1&shard={-2**63}&seqno={seqno}'
1919
if answers['network'] == 'Testnet':
2020
url = url.replace('toncenter.com', 'testnet.toncenter.com')
21-
data = requests.get(url).json()
21+
data = requests.get(url, timeout=3).json()
2222
if not data['ok']:
2323
raise Exception(f'Failed to get block: {data}')
2424
utime = int(data['result']['gen_utime'])

0 commit comments

Comments
 (0)