Skip to content

fix(symfony): ensure ErrorListener is fully stateless to prevent stat…#7921

Open
KevinMartinsDev wants to merge 1 commit intoapi-platform:mainfrom
KevinMartinsDev:fix/error-listener-stateless
Open

fix(symfony): ensure ErrorListener is fully stateless to prevent stat…#7921
KevinMartinsDev wants to merge 1 commit intoapi-platform:mainfrom
KevinMartinsDev:fix/error-listener-stateless

Conversation

@KevinMartinsDev
Copy link
Copy Markdown

Description

This PR is the third part of the worker mode compatibility audit (see #7918). It refactors the ErrorListener to be strictly stateless.

The Issue

The ErrorListener previously stored the target controller in a private property during the request duplication process. In persistent memory runtimes (FrankenPHP, Swoole, etc.):

  1. State Leakage: If an error occurred, the $controller property was mutated. If not properly reset (and it wasn't), the next error handled by the same worker could inherit the previous request's controller.
  2. Thread Safety: Mutating service properties is unsafe in multi-threaded PHP environments.

The Solution

The listener has been refactored to remove the mutable $controller property entirely:

  • Stateless logic: The choice of controller (API Platform's error handler vs. Symfony's default) is now determined locally within duplicateRequest.
  • Parent Fallback: We now explicitly call parent::duplicateRequest($exception, $request) when we need to delegate to Symfony, without modifying the listener's internal state.
  • BC Compliance: Since the property was private, removing it does not break the public API. The constructor signature remains unchanged for backward compatibility.

This ensures that every error handled by the worker starts with a "clean slate", regardless of what happened in previous requests.

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