FileMediaStore.body() kept one FileHandle for the whole response and closed it only at the end or on cancel. A player that seeks or closes mid-film often triggers neither; the handle then fell to the garbage collector, which Bun 1.4 treats as fatal. The Prism relay restarted five times this way. Each piece now opens and closes the file. Regression test runs in its own process and checks no descriptor is open between reads. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
22 lines
1.1 KiB
TypeScript
22 lines
1.1 KiB
TypeScript
import { describe, test, expect } from 'bun:test';
|
|
import { FileMediaStore } from '../src/server.js';
|
|
|
|
describe('FileMediaStore', () => {
|
|
test('a directory it cannot use fails each call with the reason, not the process', async () => {
|
|
const store = new FileMediaStore('/proc/shade-cannot-write-here');
|
|
await new Promise((r) => setTimeout(r, 20)); // an unhandled rejection would surface here
|
|
await expect(store.get('00'.repeat(16))).rejects.toThrow(/ENOENT|EACCES|EROFS|EPERM/);
|
|
await expect(store.totalBytes()).rejects.toThrow();
|
|
});
|
|
});
|
|
|
|
describe('FileMediaStore bodies', () => {
|
|
test('a body nobody finishes reading holds no file for the garbage collector to close', async () => {
|
|
const proc = Bun.spawn(['bun', 'run', `${import.meta.dir}/fixtures/abandoned-body.ts`], { stdout: 'pipe', stderr: 'pipe' });
|
|
const [out, err, code] = await Promise.all([new Response(proc.stdout).text(), new Response(proc.stderr).text(), proc.exited]);
|
|
expect(err).not.toContain('closed during garbage collection');
|
|
expect(out.trim()).toBe('survived');
|
|
expect(code).toBe(0);
|
|
}, 30_000);
|
|
});
|