Skip to content

Commit

Permalink
fix(http): clear queues after hostrules change (#17563)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Sep 1, 2022
1 parent ab47364 commit 8ad1947
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/modules/platform/github/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 7 additions & 1 deletion lib/util/http/queue.ts
Original file line number Diff line number Diff line change
@@ -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;
}

Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions lib/workers/global/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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({});
}
Expand Down
3 changes: 3 additions & 0 deletions lib/workers/repository/init/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -255,6 +256,8 @@ export async function mergeRenovateConfig(
);
}
}
// host rules can change concurrency
queue.clear();
delete resolvedConfig.hostRules;
}
returnConfig = mergeChildConfig(returnConfig, resolvedConfig);
Expand Down

0 comments on commit 8ad1947

Please sign in to comment.