Problem/Motivation

With persistent app servers like FrankenPHP worker mode, completed requests remain reachable through the renderer's static context collection, which leaks memory and can eventually crash the worker.

The collection uses SplObjectStorage, which holds strong references to request keys. Setting the context to NULL preserves the request key.

Steps to reproduce

  1. Push a new request onto the renderer's request stack and create a WeakReference to it.
  2. Call Renderer::executeInRenderContext() with an empty render context and a callback that returns normally.
  3. Pop the request, unset its local reference, and run gc_collect_cycles().
  4. The weak reference still returns the request, but it should be NULL when the reference has been released.

Proposed resolution

Replace the collection with WeakMap so its keys do not keep requests alive. Keep the collection static to preserve sharing between renderer instances.

User interface changes

None.

API changes

None. The protected Renderer::$contextCollection changes from SplObjectStorage to WeakMap, but core has no other references to it.

Data model changes

None.

AI disclosure: I used AI to help prepare the IS and MR (Astra and Opus 5.5).

Issue fork drupal-3626370

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

ptmkenny created an issue. See original summary.

ptmkenny’s picture

Status: Active » Needs review