Optimize error responses and avoid infinite loops

Created on 30 June 2025, 3 days ago

Problem/Motivation

While developing a project using this module in combination with

  • various environments in various development stages of the codebase
  • developers using DB copies from any those environments
  • developers using stage file proxy, not necessarily connecting to the correct corresponding environment

we noticed tremendous CPU usage increase on local machine and those environments, when for example a page with multiple images was requested, with both local machine and environment server eventually crashing or processes killed by safeguard mechanisms.

A direct reason of the was the databases being filled with errors (~50k records less than a minute) from various image related modules (core image, imagemagick, file_mdm) on files that could not be found.

After a lot of digging to understand what was happing, I found a few issues in the DrimageSubscriber that are part of the observed problem:

  1. Because DrimageSubscriber is an event subscriber, returned error responses are not returned right away, but are catched upstream by core and the 404 page is build and returned instead.
  2. The call to actually build the image can also throw a NotFoundHttpException, which will bubble and handle by core to also return 404 page.

Since the javascript only needs to know if the image exists or is generated, the 404 page building is unnecessary overhead.

In addition, if the 404 page contains images loaded width drimage_improved that don't exists for some reason, the process enters an infinite loop.

Steps to reproduce

  • Have a project with missing images. Removing the actual image files is the easiest way to do this
  • Make sure the 404 is supposed to show images using this module and are missing too
  • Load a page, view,... anything with one or more images that cannot be loaded
  • Observe CPU usage rising, error records being created in the watchdog, ....

Proposed resolution

  • Setting the error response on the event, instead of returning it, will cause the event to stop propagatin, return the error message and not the 404 page
  • Catching the NotFoundHttpException from the image generation and setting it on the event.

Remaining tasks

  • ✅ File an issue
  • ➖ Addition/Change/Update/Fix
  • ➖ Testing to ensure no regression
  • ➖ Automated unit testing coverage
  • ➖ Automated functional testing coverage
  • ➖ UX/UI designer responsibilities
  • ➖ Readability
  • ➖ Accessibility
  • ➖ Performance
  • ➖ Security
  • ➖ Documentation
  • ➖ Code review by maintainers
  • ➖ Full testing and approval
  • ➖ Credit contributors
  • ➖ Review with the product owner
  • ➖ Release notes snippet
  • ❌ Release

API changes

  • N/A

Data model changes

  • N/A

Release notes snippet

  • N/A
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇧🇪Belgium andreasderijcke Antwerpen / Gent

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024