Skip to content

Add a timeout to the url requests #207

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

Merged
merged 4 commits into from
Feb 6, 2023

Conversation

Jaimepas77
Copy link
Contributor

Just added a timeout to the url request so when it's not answered it doesn't wait a long time before throwing an error.

Timeout of 2 seconds.
tldr.py Outdated
@@ -160,6 +160,7 @@ def get_page_for_platform(
try:
data = urlopen(
Request(page_url, headers=REQUEST_HEADERS),
timeout = 2,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
timeout = 2,
timeout=2,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is two seconds long enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is two seconds long enough?

I think so, but i wouldn't care if it was set to 10 seconds or something like that. The problem that i saw was that, if no timeout was specified, there were some occasions where the program would get stuck for more than a minute until throwing a timeout error. However I believe that 2 seconds are more than enough.

Copy link
Collaborator

@MasterOdin MasterOdin Feb 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've bumped this up to 10 seconds as I feel like while 2 is probably fine, better to be a touch conservative and hopefully avoid any people complaining about things "suddenly" breaking on them due to timeouts, and this still at least more rapidly gets this program to crash out much more quickly.

tldr.py Outdated
Comment on lines 271 to 272
except TimeoutError:
continue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should be skipping this, in that we don't skip if we get a 500 HTTPError. Something about the upstream is broken in a way that we cannot connect to it, and I don't think we should continue on and potentially serve the wrong page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've read some more info about that and I've noticed that in fact a URLError (and not a TimeoutError) is raised when the timeout expires. Consequently I've deleted that part of the code and committed it. The behavior is that whenever a request is not answered an error message is shown to the user. Sorry for the confusion.

Jaimepas77 and others added 2 commits February 5, 2023 18:56
Co-authored-by: Matthew Peveler <[email protected]>
When the timeout expires, a URLError is thrown (not a TimeoutError).
@Jaimepas77 Jaimepas77 requested a review from MasterOdin February 5, 2023 18:32
@MasterOdin MasterOdin merged commit 2d06e4a into tldr-pages:main Feb 6, 2023
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.

3 participants