Skip to content

🎥 Make videos programmatically with React

improve

Jonny Burger9cfdfc1c8599
diff --git a/packages/lambda/src/functions/helpers/overall-render-progress.ts b/packages/lambda/src/functions/helpers/overall-render-progress.ts
index 8ea3d651e2..859178c683 100644
--- a/packages/lambda/src/functions/helpers/overall-render-progress.ts
+++ b/packages/lambda/src/functions/helpers/overall-render-progress.ts
@@ -111,18 +111,13 @@ export const makeOverallRenderProgress = ({
await currentUploadPromise;
}
- const toWrite = JSON.stringify(getCurrentProgress());
-
- // Deduplicate two fast incoming requests
- await new Promise<void>((resolve) => {
- setImmediate(() => resolve());
- });
-
// If request has been replaced by a new one
if (getLatestRequestId() !== uploadRequestId) {
return;
}
+ const toWrite = JSON.stringify(getCurrentProgress());
+
const start = Date.now();
currentUploadPromise = lambdaWriteFile({
body: toWrite,
@@ -138,7 +133,7 @@ export const makeOverallRenderProgress = ({
// By default, upload is way too fast (~20 requests per second)
// Space out the requests a bit
return new Promise<void>((resolve) => {
- setTimeout(resolve, 500 - (Date.now() - start));
+ setTimeout(resolve, 250 - (Date.now() - start));
});
})
.catch((err) => {
diff --git a/packages/lambda/src/shared/aws-clients.ts b/packages/lambda/src/shared/aws-clients.ts
index f8d1f1b1f7..658e027e3f 100644
--- a/packages/lambda/src/shared/aws-clients.ts
+++ b/packages/lambda/src/shared/aws-clients.ts
@@ -5,7 +5,9 @@ import {S3Client} from '@aws-sdk/client-s3';
import {ServiceQuotasClient} from '@aws-sdk/client-service-quotas';
import {STSClient} from '@aws-sdk/client-sts';
import {fromIni} from '@aws-sdk/credential-providers';
+import {Agent} from 'https';
import {random} from 'remotion/no-react';
+import {NodeHttpHandler} from '../functions/helpers/http-handler/custom-handler';
import type {AwsRegion} from '../pricing/aws-regions';
import {checkCredentials} from './check-credentials';
import {isInsideLambda} from './is-in-lambda';
@@ -208,12 +210,18 @@ export const getServiceClient = <T extends keyof ServiceMapping>({
const lambdaOptions =
service === 'lambda'
- ? {
- httpsAgent: {
- maxSockets: 100,
- keepAlive: false,
- },
- }
+ ? new NodeHttpHandler({
+ httpsAgent: new Agent({
+ keepAlive: true,
+ maxSockets: 300, // default is 50 per client.
+ }),
+
+ // time limit (ms) for receiving response.
+ requestTimeout: 30_000,
+
+ // time limit (ms) for establishing connection.
+ connectionTimeout: 6_000,
+ })
: undefined;
const client = customCredentials
diff --git a/packages/lambda/src/shared/call-lambda.ts b/packages/lambda/src/shared/call-lambda.ts
index 5f1a63827e..0c7b65f3a0 100644
--- a/packages/lambda/src/shared/call-lambda.ts
+++ b/packages/lambda/src/shared/call-lambda.ts
@@ -8,7 +8,6 @@ import {
InvokeWithResponseStreamCommand,
} from '@aws-sdk/client-lambda';
import {makeStreamer} from '@remotion/streaming';
-import {freemem} from 'os';
import type {OrError} from '../functions';
import type {
MessageTypeId,
@@ -76,7 +75,8 @@ export const callLambdaWithStreaming = async <T extends LambdaRoutines>(
if (
!(err as Error).message.includes(INVALID_JSON_MESSAGE) &&
- !(err as Error).message.includes(LAMBDA_STREAM_STALL)
+ !(err as Error).message.includes(LAMBDA_STREAM_STALL) &&
+ !(err as Error).message.includes('aborted')
) {
throw err;
}
@@ -186,8 +186,6 @@ const callLambdaWithStreamingWithoutRetry = async <T extends LambdaRoutines>({
? parseJsonOrThrowSource(data, messageType)
: data;
- console.log('got', data.length, freemem(), process.memoryUsage());
-
const message: StreamingMessage = {
successType: status,
message: {
@@ -227,9 +225,9 @@ const callLambdaWithStreamingWithoutRetry = async <T extends LambdaRoutines>({
`Lambda function ${functionName} failed with error code ${event.InvokeComplete.ErrorCode}: ${event.InvokeComplete.ErrorDetails}. See ${logs} to see the logs of this invocation.`,
);
}
-
- break;
}
+
+ // Don't put a `break` statement here, as it will cause the socket to not properly exit.
}
clear();