craftcms / craftcms/cms

[4.x]: Image transforms via queue - memory leak?

Open
#13,098 4 comments 0 reactions 1 assignee View on GitHub

@angrybrad is already working on this.

Since Jun 16, 2025.

bug craft4
Dominant language
PHP
Stars
3.6k
Forks
705
Avg merge
1d 5h
Merged PRs (30d)
134

Description

What happened?
Description

Not sure if this is a bug or just a matter of configuration.
We are using image transforms for our assets, they are handled via queue. We noted, that the job Generating pending image transforms needs very long for 75 images and gets canceled due to queue ttr. We already set the limit to 6000 which is still not enough. I am aware, that image transforms are expensive and it´s ok that it needs some time, however, our actual issue is, that the job is not freeing up memory after transforming or checking an image. As soon as the job gets canceled (after 6000) the memory usage drops. To me, the memory usage chart looks like it keeps already transformed images open and moves to the next one. As soon as the job timed out, memory usage dropped back to normal.
Screenshot 2023-04-19 at 11 15 17
Screenshot 2023-04-19 at 11 16 34

cat /sys/fs/cgroup/memory/memory.stat
cache 96321536
rss 3781828608
rss_huge 0
shmem 0
mapped_file 20951040
dirty 0
writeback 270336
swap 0
pgpgin 37919805
pgpgout 36972963
pgfault 38191395
pgmajfault 924
inactive_anon 0
active_anon 3780919296
inactive_file 52199424
active_file 44879872
unevictable 0
hierarchical_memory_limit 14042316800
hierarchical_memsw_limit 9223372036854771712
total_cache 96321536
total_rss 3781828608
total_rss_huge 0
total_shmem 0
total_mapped_file 20951040
total_dirty 0
total_writeback 270336
total_swap 0
total_pgpgin 37919805
total_pgpgout 36972963
total_pgfault 38191395
total_pgmajfault 924
total_inactive_anon 0
total_active_anon 3780919296
total_inactive_file 52199424
total_active_file 44879872
total_unevictable 0 
Screenshot 2023-04-19 at 11 44 04

We are using this image: craftcms/cli:8.1@sha256:1f972a7493e056a21bcc4604c0dd44c497797d9fd2fecb61f5919c263228f2ab

Steps to reproduce
  1. Create Image Transforms
  2. Upload 20+ Images
  3. Watch Generating pending image transforms
  4. Memory Usage increases
Expected behavior

Memory on server should be freed, after an image within one job gets transformed before moving to the next image within the same job

Actual behavior

Memory on server grows until job get´s killed or server runs out of memory

Craft CMS version

4.2.0.2

PHP version

8.1.9

Operating system and version

Linux 5.4.144+

Database type and version

MySQL 10.5.13

Image driver and version

Imagick 3.7.0 (ImageMagick 7.1.0-35)

Installed plugins and versions

Blitz 4.2.1
CP Field Inspect 1.4.4
Empty Coalesce 4.0.0-beta.1
ImageOptimize 4.0.2
Redactor 3.0.2
SEOmatic 4.0.7
Sprig 2.3.0
Super Table 3.0.0
Typed link field 2.1.3-rc
Vite 4.0.2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.