payloadcms / payloadcms/payload
OOM Crashes During Image Resizing
@r1tsuu is already working on this.
Since Feb 19, 2025.
- Dominant language
- TypeScript
- Stars
- 44.8k
- Forks
- 4.2k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 53
Description
Link to reproduction
No response
Environment Info
Relevant Packages:
payload: 3.0.0-beta.111
next: 15.0.0-canary.173
@payloadcms/db-postgres: 3.0.0-beta.111
@payloadcms/email-nodemailer: 3.0.0-beta.111
@payloadcms/graphql: 3.0.0-beta.111
@payloadcms/next/utilities: 3.0.0-beta.111
@payloadcms/plugin-cloud: 3.0.0-beta.111
@payloadcms/plugin-cloud-storage: 3.0.0-beta.111
@payloadcms/plugin-seo: 3.0.0-beta.111
@payloadcms/richtext-lexical: 3.0.0-beta.111
@payloadcms/translations: 3.0.0-beta.111
@payloadcms/ui/shared: 3.0.0-beta.111
react: 19.0.0-rc-3edc000d-20240926
react-dom: 19.0.0-rc-3edc000d-20240926
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:04 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6020
Available memory (MB): 65536
Available CPU cores: 12
Overview
I'm experiencing app restarts during image uploads and resizing when processing AVIF and WebP formats on DigitalOcean App Platform with 1GB RAM. When uploading an image (1.5mb) it takes about 20 seconds to resize 6 image sizes. Anything heavier in the app just crashes & restarts. I'm resizing to avif & webp which I think is causing heavy resource compute, particularly avifenc.
Observations:
- Memory Usage: The memory does not decrease after image processing, indicating a potential memory leak.
- CPU Usage: While CPU usage increases, it does not reach a point that should cause restarts. (I attached a graph of the resource usage during the process).
- Crashes: The app crashes when processing images, but no OOM or CPU pinning logs are produced.
- Timeout: Increasing server timeout in the Next.js config doesn’t seem to prevent the crashes.
Suspected Cause:
I believe the issue may stem from how Promise.all is handling multiple image sizes, which could cause a memory spike during processing, attached below, but this is just a hunch, it may not explain the leak.
imageResizer.ts.
Additional Context:
- I’ve tried tweaking the AVIF conversion settings by reducing the effort option, but the issue persists. The issue does not correlate directly to CPU or OOM spikes, making it difficult to debug.
- The issue does not seem to be prevalent when bumping the RAM, but ovbiously this is incurring more cost.
Links
Attachments
Clinic Doctor:
This profile is 30 seconds long, you can see that I uploaded an image at around 10 seconds, but the RAM hangs and does not decrease.
Digital Ocean:
Reproduction Steps
- Use 1GB Ram in container.
- Upload an image (~1.5MB) using the media upload feature in PayloadCMS.
- Resize the image to 6 different sizes, including AVIF and WebP formats.
- App crashes after 20-25 seconds and restarts.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.