mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
* fix(lint): run Studio and producer lint off the host's own thread A composition that sends the linter's parser into a runaway froze or crashed the long-lived hosts that lint it in their own process. CLI Studio's single-page lint now runs in a child process with a heap cap and a 15 s limit. Producer /lint (runHyperframeLint) runs on a worker thread with the same limits. A page that times out, runs out of memory, or whose child or thread ends without an answer gets one lint_aborted error finding and is never linted in the host process. Studio's project lint keeps its timeout and gains a heap cap. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(producer): cap concurrent /lint workers at two Each lint worker can hold up to 512 MB, so parallel /lint requests multiplied that without bound. At most two run at once; the rest wait in order, and a request still waiting when its own 15 s runs out gets the lint_aborted result. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
76 lines
2.6 KiB
TypeScript
76 lines
2.6 KiB
TypeScript
import "./utils/hideChildConsoles.js";
|
|
import "./utils/windowsExeSearch.js";
|
|
import { readFile, rm } from "node:fs/promises";
|
|
import { constants, setPriority } from "node:os";
|
|
import { lintHyperframeHtml } from "@hyperframes/lint";
|
|
import { runBrowserInstall } from "./browser/installRun.js";
|
|
import { ensureBrowser, releaseOwnedBrowserInstallLock } from "./browser/manager.js";
|
|
import { lintProject } from "./utils/lintProject.js";
|
|
import { killOrphanedProcesses } from "./utils/orphanCleanup.js";
|
|
import {
|
|
installRenderSetupSignalHandlers,
|
|
renderSetupErrorLine,
|
|
renderSetupResultLine,
|
|
} from "./renderSetupWorkerLifecycle.js";
|
|
|
|
const mode = process.argv[2];
|
|
const input = JSON.parse(process.env.HYPERFRAMES_RENDER_SETUP_INPUT ?? "{}");
|
|
|
|
const disposeSignalHandlers = installRenderSetupSignalHandlers(
|
|
process,
|
|
releaseOwnedBrowserInstallLock,
|
|
(signal) => process.kill(process.pid, signal),
|
|
process.env.HYPERFRAMES_RENDER_DETACHED !== "1",
|
|
);
|
|
|
|
const SANDBOX_REFUSED_PRIORITY = new Set(["EPERM", "EACCES"]);
|
|
|
|
function setOwnPriority(priority: number, whatStaysNormal: string): void {
|
|
try {
|
|
setPriority(priority);
|
|
} catch (error) {
|
|
if (SANDBOX_REFUSED_PRIORITY.has((error as { info?: { code?: string } }).info?.code ?? ""))
|
|
return;
|
|
process.stderr.write(`${whatStaysNormal} at normal priority: ${(error as Error).message}\n`);
|
|
}
|
|
}
|
|
|
|
async function runMode(): Promise<unknown> {
|
|
if (mode === "browser") return ensureBrowser(input);
|
|
if (mode === "browser-install") {
|
|
setOwnPriority(constants.priority.PRIORITY_ABOVE_NORMAL, "The Chrome install runs");
|
|
return runBrowserInstall(input);
|
|
}
|
|
if (mode === "lint") {
|
|
// A background lint (Studio's, preview's) takes idle CPU only; a render waits on its lint, so that one does not.
|
|
if (input.background) setOwnPriority(constants.priority.PRIORITY_LOW, "Lint runs");
|
|
return lintProject(
|
|
input.projectDir,
|
|
input.entryFile,
|
|
input.host ? { host: input.host } : undefined,
|
|
);
|
|
}
|
|
if (mode === "lint-html") {
|
|
try {
|
|
return await lintHyperframeHtml(await readFile(input.htmlPath, "utf-8"), input.opts);
|
|
} finally {
|
|
await rm(input.htmlPath, { force: true });
|
|
}
|
|
}
|
|
if (mode === "orphan-cleanup") {
|
|
const killed = killOrphanedProcesses();
|
|
if (killed > 0) await new Promise((resolve) => setTimeout(resolve, 600));
|
|
return killed;
|
|
}
|
|
throw new Error(`Unknown render setup mode: ${mode}`);
|
|
}
|
|
|
|
try {
|
|
const result = await runMode().finally(disposeSignalHandlers);
|
|
process.stdout.write(renderSetupResultLine(result));
|
|
} catch (error) {
|
|
process.stderr.write(renderSetupErrorLine(error), () => {
|
|
throw error;
|
|
});
|
|
}
|