Skip to content

🎥 Make videos programmatically with React

better diagnostics when chunks are not arriving in lambda

Jonny Burgerdb95c0c44e6d
diff --git a/packages/lambda/src/api/render-media-on-lambda.ts b/packages/lambda/src/api/render-media-on-lambda.ts
index 9acaf6c5e2..acb62f38ef 100644
--- a/packages/lambda/src/api/render-media-on-lambda.ts
+++ b/packages/lambda/src/api/render-media-on-lambda.ts
@@ -15,6 +15,7 @@ import type {OutNameInput, Privacy, WebhookOption} from '../shared/constants';
import {LambdaRoutines} from '../shared/constants';
import type {DownloadBehavior} from '../shared/content-disposition-header';
import {
+ getCloudwatchMethodUrl,
getCloudwatchRendererUrl,
getLambdaInsightsUrl,
getS3RenderUrl,
@@ -67,6 +68,7 @@ export type RenderMediaOnLambdaOutput = {
renderId: string;
bucketName: string;
cloudWatchLogs: string;
+ cloudWatchMainLogs: string;
lambdaInsightsLogs: string;
folderInS3Console: string;
};
@@ -95,6 +97,13 @@ export const internalRenderMediaOnLambdaRaw = async (
rendererFunctionName: rendererFunctionName ?? null,
chunk: null,
}),
+ cloudWatchMainLogs: getCloudwatchMethodUrl({
+ renderId: res.renderId,
+ functionName,
+ method: LambdaRoutines.launch,
+ region,
+ rendererFunctionName: rendererFunctionName ?? null,
+ }),
folderInS3Console: getS3RenderUrl({
bucketName: res.bucketName,
renderId: res.renderId,
diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.ts
index 4ad982c7b2..623529186b 100644
--- a/packages/lambda/src/functions/launch.ts
+++ b/packages/lambda/src/functions/launch.ts
@@ -4,6 +4,7 @@ import {RenderInternals} from '@remotion/renderer';
import {existsSync, mkdirSync, rmSync} from 'fs';
import {join} from 'path';
import {VERSION} from 'remotion/version';
+import type {EventEmitter} from 'stream';
import {
compressInputProps,
decompressInputProps,
@@ -432,6 +433,11 @@ export const launchHandler = async (
'Function is about to time out. Can not finish render.',
);
+ // @ts-expect-error
+ (globalThis._dumpUnreleasedBuffers as EventEmitter).emit(
+ 'dump-unreleased-buffers',
+ );
+
Promise.all(cleanupTasks)
.then(() => {
RenderInternals.Log.info(
diff --git a/packages/streaming/src/make-streamer.ts b/packages/streaming/src/make-streamer.ts
index 7c36b72164..ad4db8e44b 100644
--- a/packages/streaming/src/make-streamer.ts
+++ b/packages/streaming/src/make-streamer.ts
@@ -1,7 +1,15 @@
+import {EventEmitter} from 'stream';
+
export const streamingKey = 'remotion_buffer:';
const magicWordStr = 'remotion_buffer:';
+// @ts-expect-error
+globalThis._dumpUnreleasedBuffers = new EventEmitter();
+
+// @ts-expect-error
+(globalThis._dumpUnreleasedBuffers as EventEmitter).setMaxListeners(201);
+
export const makeStreamer = (
onMessage: (
statusType: 'success' | 'error',
@@ -111,6 +119,16 @@ export const makeStreamer = (
processInput();
};
+ const dumpBuffers = () => {
+ console.log('Request with unused data', {missingData, unprocessedBuffers});
+ };
+
+ // @ts-expect-error
+ (globalThis._dumpUnreleasedBuffers as EventEmitter).addListener(
+ 'dump-unreleased-buffers',
+ dumpBuffers,
+ );
+
const onData = (data: Uint8Array) => {
unprocessedBuffers.push(data);
const separatorIndex = data.indexOf(separator[0]);
@@ -144,6 +162,11 @@ export const makeStreamer = (
clear: () => {
unprocessedBuffers = [];
outputBuffer = new Uint8Array(0);
+ // @ts-expect-error
+ (globalThis._dumpUnreleasedBuffers as EventEmitter).removeListener(
+ 'dump-unreleased-buffers',
+ dumpBuffers,
+ );
},
};
};