Add timeout to external calls.

This commit is contained in:
Ian Walton 2020-08-14 02:39:58 -04:00
parent 96bfea0ccf
commit 825126f398
2 changed files with 3 additions and 4 deletions

View File

@ -21,7 +21,7 @@ class UpdateChecker:
def _check_updates(self):
log.info("Checking for updates...")
try:
response = requests.get(release_url + "latest", allow_redirects=False)
response = requests.get(release_url + "latest", allow_redirects=False, timeout=(3, 10))
version = response.headers["location"][len(release_url)+5:]
if CLIENT_VERSION != version:
self.new_version = version

View File

@ -1,6 +1,6 @@
import socket
import ipaddress
import urllib.request
import requests
import urllib.parse
from threading import Lock
import logging
@ -63,8 +63,7 @@ def is_local_domain(client):
if not is_local:
if addr_info[0] == socket.AddressFamily.AF_INET:
try:
wan_ip = (urllib.request.urlopen("https://checkip.amazonaws.com/")
.read().decode('ascii').replace('\n','').replace('\r',''))
wan_ip = requests.get("https://checkip.amazonaws.com/", timeout=(3, 10)).text.strip("\r\n")
return ip == wan_ip
except Exception:
log.warning("checkip.amazonaws.com is unavailable. Assuming potential WAN ip is remote.", exc_info=True)