Skip to content

Retry network failures when fetching data from FA#122

Merged
Deer-Spangle merged 1 commit intomasterfrom
retry-network-issues
Mar 15, 2024
Merged

Retry network failures when fetching data from FA#122
Deer-Spangle merged 1 commit intomasterfrom
retry-network-issues

Conversation

@Deer-Spangle
Copy link
Copy Markdown
Owner

Retry up to 5 times over up to 3 seconds when trying to fetch a page, if receiving a 502 or 520 error, or a connection reset.

Send the second request right away, but then wait half a second more for each additional request.

Worst case, this will be a total of 3 seconds of sleep. Pseudo timeline:

Attempts = 0
Sleep = 0
--
request
failure
Attempts = 1
A < 5
Sleeping 0
Sleep = 0.5
--
request
failure
Attempts = 2
A < 5
Sleeping 0.5
Sleep = 1
--
request
failure
Attempts = 3
A < 5
Sleeping 1 (total 1.5)
Sleep = 1.5
--
request
failure
Attempts = 4
A < 5
Sleeping 1.5 (total 3)
Sleep = 2
--
request
failure
Attempts = 5
A > 5
raise exception.
--
Total time taken = 3 seconds
Total requests made = 5

So that should be fine in case FA is actually down or unavailable.

In testing for other projects, I've been getting 2-4 of these kind of errors a day, which are simply exposed to users as fa_unknown , not very helpful.
Hopefully this will improve that a bit!

# Retry some types of error
if e.io.status[0] == "502" || e.io.status[0] == "520"
retry_attempts += 1
if retry_attempts < 5

Check notice

Code scanning / Rubocop

Check for conditionals that can be replaced with guard clauses.

Style/GuardClause: Use a guard clause (`raise unless retry_attempts < 5`) instead of wrapping the code inside a conditional expression.
rescue Errno::ECONNRESET => e
# Retry connection reset errors
retry_attempts += 1
if retry_attempts < 5

Check notice

Code scanning / Rubocop

Check for conditionals that can be replaced with guard clauses.

Style/GuardClause: Use a guard clause (`raise unless retry_attempts < 5`) instead of wrapping the code inside a conditional expression.
@Deer-Spangle Deer-Spangle merged commit a152e0a into master Mar 15, 2024
@Deer-Spangle Deer-Spangle deleted the retry-network-issues branch March 15, 2024 18:21
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