You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On our Discord server there has been a discussion about the Retry-After headers Spotify is sending. Reportedly they don't match the actual retry amount or the header is missing altogether (possibly also on Spotify's tracker spotify/web-api#542 and spotify/web-api#1267).
I tried to reproduce it, and managed to get the unwanted repeating retries, but not the missing retry header. Here's the code injected to RetryingSender.
def send(self, request: Request) -> Response:
if self.is_async:
return self._async_send(request)
tries = self.retries + 1
delay_seconds = 1
rate_limited = False # Track whether the last request was also a retry
while tries > 0:
r = self.sender.send(request)
if r.status_code == 429:
seconds = r.headers['Retry-After']
time.sleep(int(seconds))
print(rate_limited, seconds)
rate_limited = True
elif r.status_code >= 500 and tries > 1:
rate_limited = False
tries -= 1
time.sleep(delay_seconds)
delay_seconds *= 2
else:
return r
By tracking whether the last request was also a retry, we can see that indeed almost half of the requests are retried again.
It also seems that the retry amount in the second request is always 1, and that the repeating retry occurs more often with longer retry times. The requests are never retried thrice. And when looking at a longer series of values, the amount of retries and the share of second retries seems to have a pattern.
Everything works now because the second retries are performed, but by increasing the retry time by 1, the unnecessary retries are avoided entirely and we wait for less. For 145 retries, first retries took 450 seconds and second retries 100 seconds, but when adding the extra second the total was only 513 seconds.
So, given the possibility of missing headers and second retries, and the result of adding an extra second above, I think we should do two things:
Make the retry longer by 1 second
Have a default retry of 1 second
The text was updated successfully, but these errors were encountered:
On our Discord server there has been a discussion about the Retry-After headers Spotify is sending. Reportedly they don't match the actual retry amount or the header is missing altogether (possibly also on Spotify's tracker spotify/web-api#542 and spotify/web-api#1267).
I tried to reproduce it, and managed to get the unwanted repeating retries, but not the missing retry header. Here's the code injected to
RetryingSender
.By tracking whether the last request was also a retry, we can see that indeed almost half of the requests are retried again.
It also seems that the retry amount in the second request is always 1, and that the repeating retry occurs more often with longer retry times. The requests are never retried thrice. And when looking at a longer series of values, the amount of retries and the share of second retries seems to have a pattern.
Everything works now because the second retries are performed, but by increasing the retry time by 1, the unnecessary retries are avoided entirely and we wait for less. For 145 retries, first retries took 450 seconds and second retries 100 seconds, but when adding the extra second the total was only 513 seconds.
So, given the possibility of missing headers and second retries, and the result of adding an extra second above, I think we should do two things:
The text was updated successfully, but these errors were encountered: