Skip to content

fix(scraper): add request timeout and HTTP error handling to prevent workflow hangs#10

Open
glatinone wants to merge 2 commits into
aneasystone:mainfrom
glatinone:fix/scraper-timeout-hardening
Open

fix(scraper): add request timeout and HTTP error handling to prevent workflow hangs#10
glatinone wants to merge 2 commits into
aneasystone:mainfrom
glatinone:fix/scraper-timeout-hardening

Conversation

@glatinone

Copy link
Copy Markdown

While looking at scrape_url in scraper.py, I noticed the HTTP request to GitHub Trending doesn’t set a timeout and relies on an assert to validate the status code. Given this repository runs the scraper daily via schedule.yml, a slow or transient network condition could block the job or abort it early.

Context and impact:
: The GET call currently has no timeout, so a stalled connection can hang the job indefinitely.
: assert r.status_code == 200 raises an AssertionError on any non-200 response, exiting the run instead of skipping a problematic page.
: The notifier script (check_stars.py) already uses explicit timeouts for outbound requests, so adding the same resilience to the scraper aligns behavior across jobs.

Changes introduced:
: Add a REQUEST_TIMEOUT environment toggle with a default (15s) and pass it to requests.get.
: Replace assert with r.raise_for_status().
: Wrap the request and parsing in try/except to catch Timeout and RequestException, logging the error and returning a safe fallback structure so the loop continues for other languages.

Stability benefits:
: Prevents the scheduled workflow from hanging on slow responses, improving determinism for the daily update.
: Avoids abrupt termination on non-200 responses and gracefully skips transient failures, reducing noise and failed runs.
: Keeps behavior consistent with the existing star checker’s timeout usage, consolidating network hygiene across scripts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant