Problem/Motivation

RequestCloseSubscriber has a curious comment and does exactly one thing on kernel terminate:

  /**
   * Performs end of request tasks.
   *
   * @todo The body of this function has just been copied almost verbatim from
   *   drupal_page_footer(). There's probably a lot in here that needs to get
   *   removed/changed. Also, if possible, do more light-weight shutdowns on
   *   AJAX requests.
   *
   * @param \Symfony\Component\HttpKernel\Event\TerminateEvent $event
   *   The Event to process.
   */
  public function onTerminate(TerminateEvent $event) {
    $this->moduleHandler->writeCache();
  }

Steps to reproduce

Proposed resolution

Move writeCache() to a destruct() method in ModuleHandler.
Tag ModuleHandler for needs_destruction.
Delete RequestCloseSubscriber.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3436599

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

longwave created an issue. See original summary.

spokje’s picture

Status: Needs review » Reviewed & tested by the community

Makes sense to me, and tests are green => RTBC

alexpott’s picture

As per https://www.drupal.org/about/core/policies/core-change-policies/bc-polic... event subscribers are not part of the API so we can remove this class without a deprecation.

One thing I wonder is how will this cache be written if doing some event loop type thing with Drupal.

longwave’s picture

Does that make any difference here?

DrupalKernel::terminate():

      if ($this->prepared === TRUE) {
        $this->getHttpKernel()->terminate($request, $response);
      }
      // For destructable services, always call the destruct method if they were
      // initialized during the request. Destruction is not necessary if the
      // service was not used.
      foreach ($this->container->getParameter('kernel.destructable_services') as $id) {
        if ($this->container->initialized($id)) {
          $service = $this->container->get($id);
          $service->destruct();
        }
      }

KernelEvents::TERMINATE is fired during HttpKernel::terminate(), we've just moved the subscribed method down to the destruction loop instead.

alexpott’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

Good point. 1 less service FTW!

Committed and pushed 4a26ee1f81 to 11.x and 2505f212bf to 10.3.x. Thanks!

  • alexpott committed 2505f212 on 10.3.x
    Issue #3436599 by longwave: Replace RequestCloseSubscriber with...

  • alexpott committed 4a26ee1f on 11.x
    Issue #3436599 by longwave: Replace RequestCloseSubscriber with...
alexpott’s picture

I did check contrib... i think there are no issues with removing the class - https://git.drupalcode.org/search?group_id=2&repository_ref=&scope=blobs...

Status: Fixed » Closed (fixed)

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

eduardo morales alberti’s picture

After deploy the last version of Drupal 10.3.5 we got the following error:

Error: Class "Drupal\Core\EventSubscriber\RequestCloseSubscriber" not found in Drupal\Component\DependencyInjection\Container->createService() (line 259 of /mnt/www/html/drschar/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php) #0 /mnt/www/html/drschar/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService(Array, 'request_close_s...') #1 /mnt/www/html/drschar/docroot/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(105): Drupal\Component\DependencyInjection\Container->get('request_close_s...') #2 /mnt/www/html/drschar/vendor/symfony/http-kernel/HttpKernel.php(115): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\TerminateEvent), 'kernel.terminat...') #3 /mnt/www/html/drschar/docroot/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(63): Symfony\Component\HttpKernel\HttpKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Render\HtmlResponse)) #4 /mnt/www/html/drschar/docroot/core/lib/Drupal/Core/DrupalKernel.php(688): Drupal\Core\StackMiddleware\StackedHttpKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Render\HtmlResponse)) #5 /mnt/www/html/drschar/docroot/index.php(22): Drupal\Core\DrupalKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Render\HtmlResponse)) #6 @main.

Could it be related to any cache type?