diff --git a/src/utils/Fetcher.ts b/src/utils/Fetcher.ts index b1a4d5e..f3f8e92 100644 --- a/src/utils/Fetcher.ts +++ b/src/utils/Fetcher.ts @@ -288,13 +288,6 @@ export class Fetcher { response = await fetch(finalUrl, finalInit); } catch (error) { if (error instanceof DOMException && ['AbortError', 'TimeoutError'].includes(error.name)) { - if (tryCount < 1) { - this.logger.warn(`Retrying fetch ${init?.method ?? 'GET'} ${url} because of timeout`, ctx); - await this.sleep(333); - - return await this.fetchWithTimeout(ctx, url, init, ++tryCount); - } - await this.increaseTimeoutsCount(url); throw new TimeoutError(); } @@ -309,7 +302,7 @@ export class Fetcher { if (response.status === 429) { const retryAfter = parseInt(`${response.headers.get('retry-after')}`) * 1000; if (retryAfter <= this.MAX_WAIT_RETRY_AFTER && tryCount < 1) { - this.logger.info('Wait out rate limit', ctx); + this.logger.info(`Wait out rate limit for ${url.host}`, ctx); await this.sleep(retryAfter); @@ -317,13 +310,6 @@ export class Fetcher { } } - if (response.status >= 500 && tryCount < 3) { - this.logger.warn(`Retrying fetch ${init?.method ?? 'GET'} ${url} because of error`, ctx); - await this.sleep(333); - - return await this.fetchWithTimeout(ctx, url, init, ++tryCount); - } - return response; }; diff --git a/src/utils/dispatcher.ts b/src/utils/dispatcher.ts index 2c33b12..e15b340 100644 --- a/src/utils/dispatcher.ts +++ b/src/utils/dispatcher.ts @@ -1,17 +1,17 @@ import { socksDispatcher } from 'fetch-socks'; import { minimatch } from 'minimatch'; -import { Agent, Dispatcher, interceptors, ProxyAgent } from 'undici'; +import { Dispatcher, ProxyAgent } from 'undici'; import { Context } from '../types'; const createProxyAgent = (proxyUrl: URL): Dispatcher => { if (proxyUrl.protocol === 'socks5:') { - return socksDispatcher({ type: 5, host: proxyUrl.hostname, port: parseInt(proxyUrl.port) }, { allowH2: true }); + return socksDispatcher({ type: 5, host: proxyUrl.hostname, port: parseInt(proxyUrl.port) }); } - return new ProxyAgent({ uri: proxyUrl.href, allowH2: true }); + return new ProxyAgent({ uri: proxyUrl.href }); }; -const createBasicDispatcher = (ctx: Context, url: URL): Dispatcher => { +const createBasicDispatcher = (ctx: Context, url: URL): Dispatcher | undefined => { const proxyConfig = ctx.config['proxyConfig'] || process.env['PROXY_CONFIG']; if (proxyConfig) { @@ -29,12 +29,9 @@ const createBasicDispatcher = (ctx: Context, url: URL): Dispatcher => { return createProxyAgent(new URL(process.env['ALL_PROXY'])); } - return new Agent({ allowH2: true }); + return undefined; }; -export const createDispatcher = (ctx: Context, url: URL): Dispatcher => { - return createBasicDispatcher(ctx, url).compose( - interceptors.dns(), - interceptors.retry({ maxRetries: 3 }), - ); +export const createDispatcher = (ctx: Context, url: URL): Dispatcher | undefined => { + return createBasicDispatcher(ctx, url); };