Skip to content

Feat/reset interface metadata resolvers#7920

Open
KevinMartinsDev wants to merge 2 commits intoapi-platform:mainfrom
KevinMartinsDev:feat/reset-interface-metadata-resolvers
Open

Feat/reset interface metadata resolvers#7920
KevinMartinsDev wants to merge 2 commits intoapi-platform:mainfrom
KevinMartinsDev:feat/reset-interface-metadata-resolvers

Conversation

@KevinMartinsDev
Copy link
Copy Markdown

@KevinMartinsDev KevinMartinsDev commented Apr 19, 2026

Description

This PR is the second part of the worker mode compatibility audit (see #7918). It implements the Symfony\Contracts\Service\ResetInterface for metadata resolvers and extractors that maintain internal state.

The Issue

Several singleton services in the Metadata component use private arrays as local caches (e.g., $localIsResourceClassCache, $properties). In persistent memory runtimes like FrankenPHP or Swoole, these arrays:

  1. Grow indefinitely: Every unique class or property processed adds a new entry.
  2. Leak memory: Without a reset mechanism, the RAM usage of the worker increases linearly over time.
  3. Risk staleness: In some edge cases, internal state might persist where it shouldn't between different request contexts.

The Solution

By implementing ResetInterface, we allow the Symfony kernel to automatically call the reset() method after each request (when running in worker mode).

  • ResourceClassResolver: Clears $localMostSpecificResourceClassCache and $localIsResourceClassCache.
  • YamlPropertyExtractor: Clears the $properties cache.

This ensures a "clean slate" for every request, preventing slow memory leaks and ensuring long-term stability for high-traffic APIs.

Context

This fix is part of a global audit performed with Igor-PHP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant