From 8ad1947e4a1b334aaf9dc06a87e0c57ceecdff64 Mon Sep 17 00:00:00 2001 From: Michael Kriese <michael.kriese@visualon.de> Date: Thu, 1 Sep 2022 09:36:04 +0200 Subject: [PATCH] fix(http): clear queues after hostrules change (#17563) --- lib/modules/platform/github/index.spec.ts | 1 + lib/util/http/queue.ts | 8 +++++++- lib/workers/global/index.ts | 5 +++++ lib/workers/repository/init/merge.ts | 3 +++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/modules/platform/github/index.spec.ts b/lib/modules/platform/github/index.spec.ts index 0c615eb690..696919b49b 100644 --- a/lib/modules/platform/github/index.spec.ts +++ b/lib/modules/platform/github/index.spec.ts @@ -22,6 +22,7 @@ const githubApiHost = 'https://api.github.com'; jest.mock('delay'); jest.mock('../../../util/host-rules'); +jest.mock('../../../util/http/queue'); const hostRules: jest.Mocked<typeof _hostRules> = mocked(_hostRules); jest.mock('../../../util/git'); diff --git a/lib/util/http/queue.ts b/lib/util/http/queue.ts index e24a588a6a..71b387a93b 100644 --- a/lib/util/http/queue.ts +++ b/lib/util/http/queue.ts @@ -1,12 +1,15 @@ import PQueue from 'p-queue'; +import { logger } from '../../logger'; import { parseUrl } from '../url'; import { getRequestLimit } from './host-rules'; -const hostQueues = new Map<string | null, PQueue | null>(); +const hostQueues = new Map<string, PQueue | null>(); export function getQueue(url: string): PQueue | null { const host = parseUrl(url)?.host; if (!host) { + // should never happen + logger.debug({ url }, 'No host'); return null; } @@ -15,7 +18,10 @@ export function getQueue(url: string): PQueue | null { queue = null; // null represents "no queue", as opposed to undefined const concurrency = getRequestLimit(url); if (concurrency) { + logger.debug({ concurrency, host }, 'Using queue'); queue = new PQueue({ concurrency }); + } else { + logger.debug({ host }, 'No concurency limits'); } } hostQueues.set(host, queue); diff --git a/lib/workers/global/index.ts b/lib/workers/global/index.ts index 1ca3dfce70..75a0daf072 100644 --- a/lib/workers/global/index.ts +++ b/lib/workers/global/index.ts @@ -17,6 +17,7 @@ import { CONFIG_PRESETS_INVALID } from '../../constants/error-messages'; import { pkg } from '../../expose.cjs'; import { getProblems, logger, setMeta } from '../../logger'; import * as hostRules from '../../util/host-rules'; +import * as queue from '../../util/http/queue'; import * as repositoryWorker from '../repository'; import { autodiscoverRepositories } from './autodiscover'; import { parseConfigs } from './config/parse'; @@ -152,6 +153,10 @@ export async function start(): Promise<number> { repoConfig.hostRules.forEach((rule) => hostRules.add(rule)); repoConfig.hostRules = []; } + + // host rules can change concurrency + queue.clear(); + await repositoryWorker.renovateRepository(repoConfig); setMeta({}); } diff --git a/lib/workers/repository/init/merge.ts b/lib/workers/repository/init/merge.ts index d7b3a52ab0..2973e41c26 100644 --- a/lib/workers/repository/init/merge.ts +++ b/lib/workers/repository/init/merge.ts @@ -21,6 +21,7 @@ import { getCache } from '../../../util/cache/repository'; import { readLocalFile } from '../../../util/fs'; import { getFileList } from '../../../util/git'; import * as hostRules from '../../../util/host-rules'; +import * as queue from '../../../util/http/queue'; import type { RepoFileConfig } from './types'; async function detectConfigFile(): Promise<string | null> { @@ -255,6 +256,8 @@ export async function mergeRenovateConfig( ); } } + // host rules can change concurrency + queue.clear(); delete resolvedConfig.hostRules; } returnConfig = mergeChildConfig(returnConfig, resolvedConfig); -- GitLab