Merge remote-tracking branch 'origin/farm/1f41837c/timeout-bare-fetches'
This commit is contained in:
@@ -12,6 +12,7 @@ import { $which, APP_NAME, isEnoent, VERSION } from "@oh-my-pi/pi-utils";
|
||||
import { $ } from "bun";
|
||||
import chalk from "chalk";
|
||||
import { theme } from "../modes/theme/theme";
|
||||
import { isTimeoutError, withTimeoutSignal } from "../utils/fetch-timeout";
|
||||
|
||||
const REPO = "can1357/oh-my-pi";
|
||||
const PACKAGE = "@oh-my-pi/pi-coding-agent";
|
||||
@@ -29,6 +30,8 @@ const MISE_TOOL = "github:can1357/oh-my-pi";
|
||||
* See #1686.
|
||||
*/
|
||||
const NPM_REGISTRY = "https://registry.npmjs.org/";
|
||||
const RELEASE_METADATA_TIMEOUT_MS = 30_000;
|
||||
const BINARY_DOWNLOAD_TIMEOUT_MS = 15 * 60_000;
|
||||
|
||||
/**
|
||||
* Core native addon package. Bumped in lock-step with {@link PACKAGE} so the
|
||||
@@ -240,7 +243,17 @@ async function resolveUpdateTarget(): Promise<UpdateTarget> {
|
||||
* Uses npm instead of GitHub API to avoid unauthenticated rate limiting.
|
||||
*/
|
||||
async function getLatestRelease(): Promise<ReleaseInfo> {
|
||||
const response = await fetch(`${NPM_REGISTRY}${PACKAGE}/latest`);
|
||||
let response: Response;
|
||||
try {
|
||||
response = await fetch(`${NPM_REGISTRY}${PACKAGE}/latest`, {
|
||||
signal: withTimeoutSignal(RELEASE_METADATA_TIMEOUT_MS),
|
||||
});
|
||||
} catch (err) {
|
||||
if (isTimeoutError(err)) {
|
||||
throw new Error("Timed out fetching release info after 30s", { cause: err });
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch release info: ${response.statusText}`);
|
||||
}
|
||||
@@ -833,7 +846,18 @@ async function updateViaBinaryAt(targetPath: string, expectedVersion: string): P
|
||||
const backupPath = `${targetPath}.${Date.now()}.${process.pid}.bak`;
|
||||
console.log(chalk.dim(`Downloading ${binaryName}…`));
|
||||
|
||||
const response = await fetch(url, { redirect: "follow" });
|
||||
let response: Response;
|
||||
try {
|
||||
response = await fetch(url, {
|
||||
redirect: "follow",
|
||||
signal: withTimeoutSignal(BINARY_DOWNLOAD_TIMEOUT_MS),
|
||||
});
|
||||
} catch (err) {
|
||||
if (isTimeoutError(err)) {
|
||||
throw new Error("Timed out downloading release binary after 15 minutes", { cause: err });
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
if (!response.ok || !response.body) {
|
||||
throw new Error(`Download failed: ${response.statusText}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user