mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-10-25 00:37:44 +00:00
Add AbortSignal.timeout(30s) to fetch requests to ensure they fail fast instead of hanging indefinitely when network issues occur. This fixes issues where the action would hang and eventually get killed by GitHub Actions without a clear error message.
31 lines
851 B
TypeScript
31 lines
851 B
TypeScript
import { ProxyAgent, type RequestInit, fetch as undiciFetch } from "undici";
|
|
|
|
export function getProxyAgent() {
|
|
const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy;
|
|
if (httpProxy) {
|
|
return new ProxyAgent(httpProxy);
|
|
}
|
|
|
|
const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy;
|
|
if (httpsProxy) {
|
|
return new ProxyAgent(httpsProxy);
|
|
}
|
|
|
|
return undefined;
|
|
}
|
|
|
|
export const fetch = async (url: string, opts: RequestInit) => {
|
|
// Merge timeout signal with any existing signal from opts
|
|
const timeoutSignal = AbortSignal.timeout(30_000);
|
|
const existingSignal = opts.signal;
|
|
const mergedSignal = existingSignal
|
|
? AbortSignal.any([timeoutSignal, existingSignal])
|
|
: timeoutSignal;
|
|
|
|
return await undiciFetch(url, {
|
|
dispatcher: getProxyAgent(),
|
|
...opts,
|
|
signal: mergedSignal,
|
|
});
|
|
};
|