Imagick does not limit its memory usage, can crash php-fpm processes
Description
e.g. For a container with a 768M memory limit, uploading a 6MB GIF to the Assets section will cause the php-fpm process to exhaust all available memory then be killed.
This can be limited by setting ENV MAGICK_MEMORY_LIMIT 200M in the image (or some other sane memory limit for the use case).
Would like to suggest that this gets baked in to the image.
Steps to reproduce
- Upload a large image to the Asset library
- See 502 in the network tab, logs
[16-Nov-2022 07:27:43] WARNING: [pool www] child 30 exited on signal 9 (SIGKILL) after 161.276694 seconds from start
[16-Nov-2022 07:27:43] NOTICE: [pool www] child 35 started
2022/11/16 07:27:43 [error] 19#19: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 172.24.0.1, server: _, request: "POST /index.php?p=admin/actions/assets/upload HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost", referrer: "http://localhost/admin/assets/assets"
This happens after just a few seconds.
Additional info
- Craft version: 3.7.59
- PHP version: 7.4
- Database driver & version: MySQL 8
- Plugins & versions: N/A
- Image:
craftcms/nginx:8.0
We are facing the same issue with the 8.1 image. exact same definition and error as @OscarBarrett
Setting the ENV var as suggested helped.
i think this issue is only related to you, if you are limiting a containers resources
What a lifesaver this issue is <3 Got stuck for a few hours trying to debug this exact issue until i found this ticket.
I think baking this into the container would be a great benefit to a lot of users. Maybe configurable like the PHP memory limit and such already is.
Actually you do not need to bake it necessarily.
Just set or pass MAGICK_MEMORY_LIMIT with a sane value when starting the container or compose service etc.