Replies: 1 comment
-
async function fetch_retry (url: URL, options: RequestInit, timeout: number, retries = 0, count = 0): Promise<Response> {
try {
options.signal = AbortSignal.timeout(timeout)
return await fetch(url, options)
} catch (error) {
if (
count >= retries ||
error.name !== 'TimeoutError' && !['ECONNRESET', 'ETIMEDOUT', 'ESOCKETTIMEDOUT'].includes(error.cause?.code)
)
throw error
else {
const duration = 2 ** count
console.log(`${`wait ${duration} seconds to retry fetching (${count}) …`.yellow} ${url.toString().blue.underline}`)
await delay(1000 * duration)
return fetch_retry(url, options, timeout, retries, count + 1)
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've read some discussions (#1195) and issues, which said undici currently has retry function for socket error.
I just wonder if we can config the retry gap and limit? How does the retry works with timeout?
It seems there is no a explict place for retry code. I guess the current implementation is in
client.js
?Beta Was this translation helpful? Give feedback.
All reactions