Skip to content

Commit b58ad79

Browse files
committed
fix(studio-server): a refused proxy copy still invalidates thumbnail captures
1 parent 30fa54a commit b58ad79

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

‎packages/studio-server/src/helpers/proxyTranscoder.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,26 @@ describe("resolveProxy", () => {
563563
return { ...spy, ...(await loadModule(spy.spawn, FFMPEG_PATH)), projectDir: tmpProject() };
564564
}
565565

566+
it("moves another project's activity mark when its ask is refused, and copies it once there is room", async () => {
567+
const { calls, resolveProxy, ProxyCapacityError, proxyActivityMark, projectDir } =
568+
await oneSlot(0);
569+
const busyProject = tmpProject();
570+
const running = resolveProxy(busyProject, clips(busyProject, ["running"]).running!);
571+
const target = clips(projectDir, ["target"]).target!;
572+
const before = proxyActivityMark(projectDir);
573+
574+
await expect(resolveProxy(projectDir, target)).rejects.toBeInstanceOf(ProxyCapacityError);
575+
expect(proxyActivityMark(projectDir)).not.toBe(before);
576+
577+
succeed(calls[0]!);
578+
await running;
579+
const retry = resolveProxy(projectDir, target);
580+
await flush();
581+
expect(calls.map(clipOf)).toEqual(["running", "target"]);
582+
succeed(calls[1]!);
583+
await retry;
584+
});
585+
566586
it("starts a priority copy before queued thumbnails, even when the queue is full", async () => {
567587
const { calls, resolveProxy, ProxyCapacityError, projectDir } = await oneSlot(1);
568588
const clip = clips(projectDir, ["running", "thumb", "late", "preview"]);

‎packages/studio-server/src/helpers/proxyTranscoder.ts‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -539,14 +539,14 @@ async function transcodeToCache(
539539
}
540540
}
541541

542-
let settledProxyCount = 0;
542+
let proxyActivity = 0;
543543

544-
/** Null while a copy for this project is being made; otherwise a mark that moves when any copy finishes. */
544+
/** Null while this project has a copy in progress; otherwise a mark that moves when any copy finishes or is refused. */
545545
export function proxyActivityMark(projectDir: string): string | null {
546-
if (!existsSync(projectDir)) return String(settledProxyCount);
546+
if (!existsSync(projectDir)) return String(proxyActivity);
547547
const cacheDir = join(realpath(projectDir), CACHE_DIR_NAME) + sep;
548548
for (const cachePath of inFlight.keys()) if (cachePath.startsWith(cacheDir)) return null;
549-
return String(settledProxyCount);
549+
return String(proxyActivity);
550550
}
551551

552552
/**
@@ -585,7 +585,10 @@ export async function resolveProxy(
585585

586586
let entry = inFlight.get(cachePath);
587587
if (!entry) {
588-
if (!options.priority && queueIsFull()) throw new ProxyCapacityError();
588+
if (!options.priority && queueIsFull()) {
589+
proxyActivity += 1;
590+
throw new ProxyCapacityError();
591+
}
589592
const job: ProxyJob = {
590593
cachePath,
591594
priority: options.priority === true,
@@ -605,7 +608,7 @@ export async function resolveProxy(
605608
})
606609
.finally(() => {
607610
forget(job);
608-
settledProxyCount += 1;
611+
proxyActivity += 1;
609612
});
610613
entry = { promise, job };
611614
inFlight.set(cachePath, entry);

0 commit comments

Comments
 (0)