fix(scraper): add request timeout and HTTP error handling to prevent workflow hangs#10
Open
glatinone wants to merge 2 commits into
Open
fix(scraper): add request timeout and HTTP error handling to prevent workflow hangs#10glatinone wants to merge 2 commits into
glatinone wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.