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

Add default session timeout 3s. #672

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
10 changes: 6 additions & 4 deletions discord/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@
def _to_json(obj: Any) -> str:
return orjson.dumps(obj, default=_handle_metadata).decode('utf-8')

_from_json = orjson.loads # type: ignore

Check warning on line 728 in discord/utils.py

View workflow job for this annotation

GitHub Actions / check

Unnecessary "# type: ignore" comment

else:

Expand Down Expand Up @@ -1450,11 +1450,12 @@
FALLBACK_BROWSER_VERSION = '120.0.0.1'
_SENTRY_ASSET_REGEX = re.compile(r'assets/(sentry\.\w+)\.js')
_BUILD_NUMBER_REGEX = re.compile(r'buildNumber\D+(\d+)"')
_DEFAULT_SESSION_TIMEOUT = 3


async def _get_info(session: ClientSession) -> Tuple[Dict[str, Any], str]:
try:
async with session.post('https://cordapi.dolfi.es/api/v2/properties/web', timeout=5) as resp:
async with session.post('https://cordapi.dolfi.es/api/v2/properties/web', timeout=_DEFAULT_SESSION_TIMEOUT) as resp:
json = await resp.json()
return json['properties'], json['encoded']
except Exception:
Expand Down Expand Up @@ -1494,14 +1495,14 @@

async def _get_build_number(session: ClientSession) -> int:
"""Fetches client build number"""
async with session.get('https://discord.com/login') as resp:
async with session.get('https://discord.com/login', timeout=_DEFAULT_SESSION_TIMEOUT) as resp:
app = await resp.text()
match = _SENTRY_ASSET_REGEX.search(app)
if match is None:
raise RuntimeError('Could not find sentry asset file')
sentry = match.group(1)

async with session.get(f'https://discord.com/assets/{sentry}.js') as resp:
async with session.get(f'https://discord.com/assets/{sentry}.js', timeout=_DEFAULT_SESSION_TIMEOUT) as resp:
build = await resp.text()
match = _BUILD_NUMBER_REGEX.search(build)
if match is None:
Expand All @@ -1512,7 +1513,8 @@
async def _get_browser_version(session: ClientSession) -> str:
"""Fetches the latest Windows 10/Chrome major browser version."""
async with session.get(
'https://versionhistory.googleapis.com/v1/chrome/platforms/win/channels/stable/versions'
'https://versionhistory.googleapis.com/v1/chrome/platforms/win/channels/stable/versions',
timeout=_DEFAULT_SESSION_TIMEOUT
) as response:
data = await response.json()
major = data['versions'][0]['version'].split('.')[0]
Expand Down
Loading