@remotion/lambda: Clean up generated site bundles - #9569
Merged
Conversation
Contributor
There was a problem hiding this comment.
Reviewed changes — adds lifecycle-aware cleanup of internally generated deploySite() bundle directories, ensuring bundles are removed on both success and failure while letting concurrent listing, upload, and stale-file deletion work settle before cleanup runs.
- New
waitForPromisesToFinishutility — wrapsPromise.alland drains remaining promises viaPromise.allSettledbefore rethrowing, so in-flight concurrent work (bundling, listing, uploads, deletions) always settles before the caller proceeds to cleanup. - Early
onDirectoryCreatedcapture indeploy-site.ts— records the generated bundle directory via the bundler's existingonDirectoryCreatedcallback (fired afterprepareOutDircreates the directory on disk), so the path is known even if bundling subsequently fails. - Discriminated-union deployment outcome in
deploy-site.ts—.then()maps success/failure ofdeploySiteWithBundleinto{type, result/error}so cleanup always runs synchronously after the deployment settles; throwsAggregateErrorwhen both deployment and cleanup fail, preserving the deployment error ascause. waitForPromisesToFinishintegration indeploy-site-with-bundle.ts— applied to the concurrentlistObjects/getBundlepair and to thedeleteFilepromises, so stale-file deletions and bundling finish before the error (or cleanup) path is reached.try/finallyaround uploads inupload-dir.ts— ensuresclearIntervalfires on the progress timer regardless of upload outcome.- Comprehensive test coverage — unit test for
waitForPromisesToFinish; integration tests for bundling failure, listing failure with pending bundling, upload failure, stale-file deletion failure (verifying the bundle directory survives deletions), successful cleanup, cleanup failure after success, and the dual-failureAggregateErrorpath.
✅ No new issues found.
DeepSeek Pro (free via Pullfrog for OSS) (Claude Opus not used — the program covers this model; add its provider key to run your pick) | 𝕏
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
deploySite()bundle directories as soon as the bundler creates themWhy
deploySite()writes generated bundles to a directory underos.tmpdir(), but this only selects a conventional temporary location. Node.js does not automatically remove directories created there when an operation finishes, the process exits, or an error occurs.Operating-system cleanup is platform-dependent and may happen only periodically, after a reboot, or not at all. Long-running deployment services, CI workers, and reused containers can therefore accumulate large Remotion bundles and eventually exhaust disk space. This change makes cleanup deterministic once all bundling and deployment work has settled, while leaving caller-owned bundle directories untouched.
Verification
bun run buildbun run stylecheckbun test packages/lambda/src/test/unitbun test packages/lambda/src/test/unit/wait-for-promises-to-finish.test.ts packages/lambda/src/test/integration/deploy-site.test.ts packages/lambda/src/test/integration/deploy-site-from-bundle.test.tsCloses #9423