Out of memory error on CSV product images import

in Troubleshooting

If you run in out-of-memory (OOM) errors during the product image import, chances are you are running into a bug in Magento regarding image conversion during CSV imports.

In the Magento admin backend, it appears as if your csv import is still running, but in the error logs you’ll notice errors that appeared during the import.

recv() failed (104: Connection reset by peer) while reading response header from upstream

In the access logging a 502 status code is returned.

This error is caused by a bug in the Gd2.php library Magento uses to convert image formats.

To fix this issue, use the instructions to fix this bug.

Instructions for manual repair

  • Create the new destination for this file:
    mkdir -p /data/web/public/app/code/local/Varien/Image/Adapter
  • Copy the Gd2.php file to it’s destination:
    cp /data/web/public/lib/Varien/Image/Adapter/Gd2.php /data/web/public/app/code/local/Varien/Image/Adapter/Gd2.php
  • open /data/web/public/app/code/local/Varien/Image/Adapter/Gd2.php with your favorite editor:
    sensible-editor /data/web/public/app/code/local/Varien/Image/Adapter/Gd2.php
  • Go to register_shutdown_function on line 49 and change this line:

    register_shutdown_function(array($this, 'destruct'));


    // register_shutdown_function(array($this, 'destruct'));
  • Keep the file open in your editor, and change line 55:

    public function destruct()


    public function __destruct()

This should lower the memory of the image resize functionality drastically.

This issue was found and solved with lots of help from Jan Buelens, working for our partner PHPro