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 drimage_improved-1.0.8

API changes

  • N/A

Data model changes

  • N/A

Release notes snippet

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

andreasderijcke created an issue. See original summary.

andreasderijcke changed the visibility of the branch 3533143-optimize-error-responses to hidden.

andreasderijcke changed the visibility of the branch 3533143-optimize-error-responses to active.

andreasderijcke’s picture

Status: Active » Needs review
rajab natshah’s picture

rajab natshah’s picture

Thank you, Andreas, for filing and the MR for this issue.

rajab natshah’s picture

Assigned: Unassigned » josebc
Issue summary: View changes
Issue tags: +drimage_improved-1.0.8
rajab natshah’s picture

Assigned: josebc » Unassigned
Status: Needs review » Fixed
rajab natshah’s picture

Issue summary: View changes

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.