Exponential backoff on waiting between 429 Errors in connection.js
This commit is contained in:
committed by
Michael Vines
parent
dbd079f54c
commit
4593c3a172
@ -509,21 +509,23 @@ function createRpcRequest(url): RpcRequest {
|
|||||||
try {
|
try {
|
||||||
let too_many_requests_retries = 5;
|
let too_many_requests_retries = 5;
|
||||||
let res = {};
|
let res = {};
|
||||||
|
let waitTime = 500;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
res = await fetch(url, options);
|
res = await fetch(url, options);
|
||||||
if (
|
if (
|
||||||
res.status !== 429 /* Too many requests */ ||
|
res.status !== 429 /* Too many requests */
|
||||||
too_many_requests_retries === 0
|
|
||||||
) {
|
) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
|
||||||
`Server responded with ${res.status} ${res.statusText}. Retrying after brief delay...`,
|
|
||||||
);
|
|
||||||
await sleep(500);
|
|
||||||
too_many_requests_retries -= 1;
|
too_many_requests_retries -= 1;
|
||||||
|
if (too_many_requests_retries === 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
console.log(
|
||||||
|
`Server responded with ${res.status} ${res.statusText}. Retrying after ${waitTime}ms delay...`,
|
||||||
|
);
|
||||||
|
await sleep(waitTime);
|
||||||
|
waitTime *= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
const text = await res.text();
|
const text = await res.text();
|
||||||
|
Reference in New Issue
Block a user