Skip to content

Commit

Permalink
refactor: Adjust download retry policy
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Mar 6, 2024
1 parent 9e15776 commit f5403b9
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions xmcl-runtime/network/pluginNetworkInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ export const pluginNetworkInterface: LauncherAppPlugin = (app) => {
}
options.headers = headers
}
const agentOptions = getDefaultAgentOptions()

const apiAgentOptions = getDefaultAgentOptions()
const apiDispatcher = new CacheDispatcher(new ProxyAgent({
controller: proxy,
factory: (connect) => new Agent({
interceptors: {
Agent: [...agentOptions.interceptors.Agent],
Client: [...agentOptions.interceptors.Client, createInterceptOptionsInterceptor([appendUserAgent, ...dispatchInterceptors])],
Agent: [...apiAgentOptions.interceptors.Agent],
Client: [...apiAgentOptions.interceptors.Client, createInterceptOptionsInterceptor([appendUserAgent, ...dispatchInterceptors])],
},
pipelining: 1,
bodyTimeout: 20_000,
Expand All @@ -103,13 +104,28 @@ export const pluginNetworkInterface: LauncherAppPlugin = (app) => {
}), new JsonCacheStorage(cache))
setGlobalDispatcher(apiDispatcher)

const downloadAgentOptions = getDefaultAgentOptions({
maxTimeout: 60_000,
errorCodes: [
'ECONNRESET',
'ECONNREFUSED',
'ENOTFOUND',
'ENETDOWN',
'ENETUNREACH',
'EHOSTDOWN',
'EHOSTUNREACH',
'EPIPE',
'UND_ERR_CONNECT_TIMEOUT',
],
maxRetries: 30,
})
const downloadProxy = new ProxyAgent({
controller: proxy,
factory: (connect) => new Agent({
connections: agentOptions.connections,
connections: downloadAgentOptions.connections,
interceptors: {
Agent: [...agentOptions.interceptors.Agent],
Client: [...agentOptions.interceptors.Client],
Agent: [...downloadAgentOptions.interceptors.Agent],
Client: [...downloadAgentOptions.interceptors.Client],
},
headersTimeout: 15_000,
connectTimeout: 35_000,
Expand Down

0 comments on commit f5403b9

Please sign in to comment.