Skip to content

The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.

Render: a page Windows had no network buffer for is loaded again; a film's poster is written before its frame counts as made (#212)

riverisbuilding037b128e149e
diff --git a/.changeset/page-load-buffer-space.md b/.changeset/page-load-buffer-space.md
new file mode 100644
index 0000000..0becc7f
--- /dev/null
+++ b/.changeset/page-load-buffer-space.md
@@ -0,0 +1,5 @@
+---
+"openfilm": patch
+---
+
+On Windows, a page the system briefly had no network buffer for (`net::ERR_NO_BUFFER_SPACE`) is loaded again, in `look`, Studio's thumbnails and exports, instead of failing. A project's card no longer misses its film's poster when it is asked for at the moment the poster is being written.
diff --git a/packages/openfilm/src/host.mjs b/packages/openfilm/src/host.mjs
index 5cab5c6..6c5d197 100644
--- a/packages/openfilm/src/host.mjs
+++ b/packages/openfilm/src/host.mjs
@@ -333,6 +333,9 @@ export async function closeBrowsers() {
*/
const READY_MS = 60_000;
+/** How many times a page is loaded when the system has no network buffer for it (FilmPage.open). */
+const OPEN_TRIES = 3;
+
/** How long a frame's picture may take once it is drawn. */
const CAPTURE_MS = 30_000;
@@ -426,8 +429,17 @@ export class FilmPage {
}
});
}
- /* a page that never loads is closed: its tab would go on running */
- await film.page.goto(new URL(entry, origin + '/').href, { waitUntil: 'load', timeout: 60_000 }).catch(async (e) => { await film.context.close(); throw e; });
+ /* a page that never loads is closed: its tab would go on running. Windows sometimes has no socket buffer free for
+ a moment (net::ERR_NO_BUFFER_SPACE, seen with many browsers or servers at once): that page is loaded again */
+ for (let tries = 1; ; tries++) {
+ const missed = await film.page.goto(new URL(entry, origin + '/').href, { waitUntil: 'load', timeout: 60_000 }).then(() => null, (e) => e);
+ if (!missed) break;
+ if (tries === OPEN_TRIES || !/net::ERR_NO_BUFFER_SPACE/.test(String(missed?.message))) {
+ await film.context.close();
+ throw missed;
+ }
+ await new Promise((r) => setTimeout(r, 500 * tries));
+ }
/* what else the page said, once (not what `said` already says), and failed files by their path in the folder */
const failed = (said = '') => {
const req = [...new Set(problems.filter((p) => p.kind === 'request').map((p) => p.message.replace(`${origin}/`, '')))]
diff --git a/packages/openfilm/src/timeline.test.mjs b/packages/openfilm/src/timeline.test.mjs
index 70aa555..9c70ca2 100644
--- a/packages/openfilm/src/timeline.test.mjs
+++ b/packages/openfilm/src/timeline.test.mjs
@@ -599,6 +599,43 @@ test('a film of many pages keeps only a few open: one far from the playhead is c
}
});
+test('a page Windows had no network buffer for (net::ERR_NO_BUFFER_SPACE) is loaded again; another failure is not', { timeout: 60_000 }, async () => {
+ const dir = mkdtempSync(join(tmpdir(), 'of-no-buffer-'));
+ writeFileSync(join(dir, 'p.html'), page('hello', 1));
+ const site = await serve(dir);
+ const browser = await launch();
+ /** The browser, its pages' first `n` loads failing with `why` as Chromium says it. */
+ const failing = (/** @type {number} */ n, /** @type {string} */ why) => {
+ const loads = { count: 0 };
+ return { loads, browser: /** @type {any} */ ({ newContext: async (/** @type {any} */ o) => {
+ const context = await browser.newContext(o);
+ const newPage = context.newPage.bind(context);
+ context.newPage = async () => {
+ const p = await newPage();
+ const goto = p.goto.bind(p);
+ p.goto = async (url, opts) => (++loads.count <= n ? Promise.reject(new Error(`page.goto: ${why} at ${url}`)) : goto(url, opts));
+ return p;
+ };
+ return context;
+ } }) };
+ };
+ try {
+ let f = failing(2, 'net::ERR_NO_BUFFER_SPACE');
+ const film = await FilmPage.open(f.browser, site.url, 'p.html');
+ assert.equal(film.meta.duration, 1);
+ assert.equal(f.loads.count, 3);
+ await film.close();
+ f = failing(3, 'net::ERR_NO_BUFFER_SPACE');
+ await assert.rejects(FilmPage.open(f.browser, site.url, 'p.html'), /ERR_NO_BUFFER_SPACE/);
+ f = failing(1, 'net::ERR_CONNECTION_REFUSED');
+ await assert.rejects(FilmPage.open(f.browser, site.url, 'p.html'), /ERR_CONNECTION_REFUSED/);
+ assert.equal(f.loads.count, 1);
+ } finally {
+ await browser.close();
+ await site.close();
+ }
+});
+
test('a host waits for a film as long as it keeps loading; a page that never gets further fails in time', { timeout: 60_000 }, async () => {
const dir = mkdtempSync(join(tmpdir(), 'of-progress-'));
/* five pages ready one after another, 0.5 s apart: 2.5 s in all, longer than the host waits without news */
diff --git a/packages/openfilm/studio/server/pageframes.mjs b/packages/openfilm/studio/server/pageframes.mjs
index 8941d6d..0cecedb 100644
--- a/packages/openfilm/studio/server/pageframes.mjs
+++ b/packages/openfilm/studio/server/pageframes.mjs
@@ -108,13 +108,14 @@ export async function pageFrame(root, base, rel, ms, width, overrides = null, si
await mkdir(dir, { recursive: true });
await writeAtomic(file, jpeg);
await writeAtomic(join(dir, `${key}.json`), JSON.stringify({ files: deps }));
- await writeAtomic(join(dir, `${key}.stamp`), await stampOf(root, deps));
if (rel === FILM_PAGE) {
/* the whole film's length, learnt on the way: the projects list shows it (projects.mjs filmDuration) */
if (Number.isFinite(duration)) await writeAtomic(join(root, TOOL_DIR, 'cache', FILM_DURATION), JSON.stringify({ film: `${info.mtimeMs}:${info.size}`, duration }));
/* the film's poster, kept as its last whatever film.html becomes (filmPoster) */
if (ms < 0 && w === POSTER_W) await writeAtomic(join(root, TOOL_DIR, 'cache', FILM_POSTER), jpeg);
}
+ /* the stamp last: a request that finds it takes the frame as made, the film's length and poster written too */
+ await writeAtomic(join(dir, `${key}.stamp`), await stampOf(root, deps));
return jpeg;
})();
drawing.set(id, made);