Skip to content

Commit b8d2275

Browse files
committed
Fix for screenshots
1 parent aaac132 commit b8d2275

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

apps/gif-service/src/gif-generator.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ export class GIFGenerator {
265265
const ff = spawn('ffmpeg', args, { stdio: ['pipe', 'ignore', 'pipe'] });
266266
let stderr = '';
267267
ff.stderr.on('data', (d) => { stderr += d.toString(); });
268+
ff.stdin.on('error', () => undefined); // EPIPE if ffmpeg exits early; close handler reports status
268269

269270
const finished = new Promise<void>((resolve, reject) => {
270271
ff.on('error', reject);
@@ -322,6 +323,9 @@ export class GIFGenerator {
322323
const ff = spawn('ffmpeg', args, { stdio: ['pipe', 'ignore', 'pipe'] });
323324
let stderr = '';
324325
ff.stderr.on('data', (d) => { stderr += d.toString(); });
326+
// If ffmpeg exits early the stdin write EPIPEs; swallow it (the close
327+
// handler reports the real status) so it can't crash the process.
328+
ff.stdin.on('error', () => undefined);
325329
const finished = new Promise<void>((resolve, reject) => {
326330
ff.on('error', reject);
327331
ff.on('close', (code) =>

apps/gif-service/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import projectRoutes from './routes/project.js';
55
import sourceRoutes from './routes/source.js';
66
import screenshotRoutes from './routes/screenshot.js';
77

8+
// Safety net: a single bad render must never take down the whole service. Log
9+
// and keep serving rather than letting an unhandled error exit the process
10+
// (each request is independent and stateless).
11+
process.on('unhandledRejection', (reason) => console.error('Unhandled rejection:', reason));
12+
process.on('uncaughtException', (err) => console.error('Uncaught exception:', err));
13+
814
const app = express();
915
const PORT = process.env.PORT || 5001;
1016

apps/gif-service/src/routes/screenshot.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ router.get('/:id', async (req: Request, res: Response) => {
6363
return out;
6464
});
6565
inFlight.set(key, pending);
66-
pending.finally(() => inFlight.delete(key));
66+
// Clear the slot when done. The trailing .catch is essential: the
67+
// real error is surfaced via `await pending` below, but this
68+
// derived promise would otherwise reject unhandled and crash the
69+
// process (Node exits on unhandledRejection).
70+
pending.finally(() => inFlight.delete(key)).catch(() => undefined);
6771
}
6872
png = await pending;
6973
}

0 commit comments

Comments
 (0)