Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

client: Add retry logic on Pubsub 429 error during connect#19990

Merged
joncinque merged 1 commit intosolana-labs:masterfrom
joncinque:pubsub-429
Sep 18, 2021
Merged

client: Add retry logic on Pubsub 429 error during connect#19990
joncinque merged 1 commit intosolana-labs:masterfrom
joncinque:pubsub-429

Conversation

@joncinque
Copy link
Copy Markdown
Contributor

@joncinque joncinque commented Sep 17, 2021

Problem

The pubsub client can give a 429 (TOO_MANY_REQUESTS) when trying to connect, causing avoidable failures to users.

Summary of Changes

Respect the backoff from a 429, and retry the connection after waiting. This mimics the send retry logic at

if response.status() == StatusCode::TOO_MANY_REQUESTS
&& too_many_requests_retries > 0
{
let mut duration = Duration::from_millis(500);
if let Some(retry_after) = response.headers().get(RETRY_AFTER) {
if let Ok(retry_after) = retry_after.to_str() {
if let Ok(retry_after) = retry_after.parse::<u64>() {
if retry_after < 120 {
duration = Duration::from_secs(retry_after);
}
}
}
}
too_many_requests_retries -= 1;
debug!(
"Too many requests: server responded with {:?}, {} retries left, pausing for {:?}",
response, too_many_requests_retries, duration
);
sleep(duration);
continue;

Fixes #

@joncinque joncinque added the v1.7 label Sep 17, 2021
@joncinque joncinque requested a review from mvines September 17, 2021 21:08
@joncinque joncinque changed the title client: Add retry logic on Pubsub 429 connection client: Add retry logic on Pubsub 429 error during connect Sep 17, 2021
Copy link
Copy Markdown
Contributor

@mvines mvines left a comment

Choose a reason for hiding this comment

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

sweet!

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 18, 2021

Codecov Report

Merging #19990 (b2304c9) into master (4675fa6) will increase coverage by 0.0%.
The diff coverage is 80.2%.

@@           Coverage Diff            @@
##           master   #19990    +/-   ##
========================================
  Coverage    82.6%    82.6%            
========================================
  Files         478      480     +2     
  Lines      133547   133674   +127     
========================================
+ Hits       110369   110514   +145     
+ Misses      23178    23160    -18     

@joncinque joncinque merged commit e9b066d into solana-labs:master Sep 18, 2021
@joncinque joncinque deleted the pubsub-429 branch September 18, 2021 10:40
mergify Bot pushed a commit that referenced this pull request Sep 18, 2021
mergify Bot added a commit that referenced this pull request Sep 20, 2021
…19990) (#20002)

* client: Add retry logic on Pubsub 429s (#19990)

(cherry picked from commit e9b066d)

* Use exponential backoff for older version of tungstenite

Co-authored-by: Jon Cinque <jon.cinque@gmail.com>
dankelleher pushed a commit to identity-com/solana that referenced this pull request Nov 24, 2021
frits-metalogix added a commit to identity-com/solana that referenced this pull request Nov 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants