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
- Push a new request onto the renderer's request stack and create a
WeakReferenceto it. - Call Renderer::executeInRenderContext() with an empty render context and a callback that returns normally.
- Pop the request, unset its local reference, and run
gc_collect_cycles(). - The weak reference still returns the request, but it should be
NULLwhen 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
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
Comment #3
ptmkenny commented