mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-02 02:29:51 +00:00
4f55ef29cf
`hostRules.find()` only lets a rule through when the rule has no `hostType` or its `hostType` equals the one being searched for. A search that passes only a `url` therefore silently ignores every `hostType`-scoped rule, even one whose `matchHost` matches exactly. Behaviour changes - `hostType`-scoped host rules now apply at these sites: - `mix`: a `hostType: 'hex'` rule for an organization repo URL is now used to authenticate against that organization. - `pre-commit`: the pre-check that returned `unknown-registry` before the `hostType`-scoped loop is dropped, so a `hostType`-only forgejo, github or gitlab rule now resolves the datasource instead of being skipped. - `util/http/github.ts`: the rate-limit warning now sees the rule `GITHUB_COM_TOKEN` registers (`hostType: 'github'`), so it reports "even though we are authenticated" rather than asking for that token. - `util/http` rate limits: `concurrentRequestLimit` and `maxRequestsPerSecond` are read with the `hostType` of the `Http` instance making the request. The queue and throttle maps stay keyed by host alone, because concurrency is a property of the remote server. The unscoped find in `pip-compile` is replaced separately, together with the other Python index credential lookups.
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import PQueue from 'p-queue';
|
|
import { logger } from '../../logger/index.ts';
|
|
import { parseUrl } from '../url.ts';
|
|
import { getConcurrentRequestsLimit } from './rate-limits.ts';
|
|
|
|
const hostQueues = new Map<string, PQueue | null>();
|
|
|
|
/**
|
|
* The queue limiting how many requests may be in flight against `url`'s host.
|
|
*
|
|
* `hostType` only selects which host rules the limit is read from. The queue
|
|
* stays keyed by host alone, because concurrency is a property of the remote
|
|
* server rather than of the module talking to it, so a host reached under
|
|
* several `hostType`s keeps the limit of whichever request created its queue.
|
|
*/
|
|
export function getQueue(url: string, hostType?: string): PQueue | null {
|
|
const host = parseUrl(url)?.host;
|
|
if (!host) {
|
|
// should never happen
|
|
logger.debug(`No host on ${url}`);
|
|
return null;
|
|
}
|
|
|
|
let queue = hostQueues.get(host);
|
|
if (queue === undefined) {
|
|
queue = null; // null represents "no queue", as opposed to undefined
|
|
const concurrency = getConcurrentRequestsLimit(url, hostType);
|
|
if (concurrency) {
|
|
logger.debug(`Using queue: host=${host}, concurrency=${concurrency}`);
|
|
queue = new PQueue({ concurrency });
|
|
} else {
|
|
logger.trace({ host }, 'No concurrency limits');
|
|
}
|
|
}
|
|
hostQueues.set(host, queue);
|
|
|
|
return queue;
|
|
}
|
|
|
|
export function clear(): void {
|
|
hostQueues.clear();
|
|
}
|