Infinite loop with custom DefaultExceptionHtmlSubscriber and JSON:API\REST endpoint

Created on 12 March 2024, about 1 year ago

Problem/Motivation

The site ends up in a infinite loops while using a custom class extending DefaultExceptionHtmlSubscriber and JSON:API or REST resource.

Steps to reproduce

Implement a basic subscriber extending DefaultExceptionHtmlSubscriber

final class MyEventSubscriber extends DefaultExceptionHtmlSubscriber {
  /**
   * {@inheritdoc}
   */
  protected static function getPriority() {
    return 100;
  }

  public function on403(ExceptionEvent $event) {
    //some code
  }

  /**
   * {@inheritdoc}
   */
  protected function getHandledFormats() {
    return [];
  }

}

GET some JSON:API or REST resource which throws a 40x exception.
402, 404, 405 will return

: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 69632 bytes) in
on line

401 or 403 error still work.

🐛 Bug report
Status

Active

Version

10.2

Component
Routing 

Last updated 4 days ago

Created by

🇮🇹Italy Giuseppe87

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

Comments & Activities

  • Issue created by @Giuseppe87
  • There is not enough here for a bug report. What is in some code?

  • 🇮🇹Italy Giuseppe87

    I've updated the example with the actual code I used to cause this behaviour.

  • 🇮🇹Italy Giuseppe87

    As workaround I've found that limiting the handled formats to 'html' wont' cause the loop.

    E.g.

      protected function getHandledFormats() {
        return ['html'];
      }
    

    or just don't overriding the method of the parent class.

    This obliviously works only if the subscriber doesn't need to intercept json\rest request. I haven't tested the case a json\rest request is handled inside the on403 on404 methods.

  • Status changed to Closed: outdated 4 months ago
  • 🇳🇿New Zealand quietone

    @Giuseppe87, thanks for reporting back what you did to fix this on your site. To me that resolves this support request, so I am closing this issue.

    If anyone is experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue starting from "Install Drupal core". It would also help to search for duplicate issues.

    Thanks!

Production build 0.71.5 2024