Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EventDispatcher] EventSubscriberInterface::getSubscribedEvents() cannot be dynamic #35579

Closed
alex-dev opened this issue Feb 3, 2020 · 7 comments

Comments

@alex-dev
Copy link
Contributor

alex-dev commented Feb 3, 2020

Symfony version(s) affected: 3.3 and up.

Description
Currently, RegisterListenersPass call EventSubscriberInterface::getSubscribedEvents() and map each event to a clear EventDispatcherInterface::addListener(). It was potentially done as a performance optimization.
Therefore, subscribed events cannot be dynamic in a EventSubscriberInterface. I cannot find reference if it is intended or not.

Event subscribers in error
On Symfony 4.4:

  • DebugHandlersListener uses PHP_SAPI to choose if it should subscribe to ConsoleEvents::COMMAND. DebugHandlersListener::configure()is therefore not called during a console command if the container was compiled by an HTTP request. Bad.
  • Flex checks if it is active through a static. Very bad. But I don't know Flex well enough to say if it is a problem in a normal flow.
  • DumpListener checks if a ConsoleEvents exists. Acceptable. Container should be recompiled if a new composer package is installed.
  • DispatchPcntlSignalListener and StopWorkerOnSigtermSignalListener check if a pcntl function is available. Acceptable. If PHP extensions or environment changes, container recompilation could be developper responsability.

Possible Solution
Either fully allows dynamic subscribers or fully disallows it. Both would require a documentation update and a fix to either of the issues described above.

@alex-dev
Copy link
Contributor Author

alex-dev commented Feb 3, 2020

I am willing to work on it. Just need to know which behavior we want.

@nicolas-grekas
Copy link
Member

Bad, very bad or fine to you isn't a description of a problem.
If you have an actual real world use case, please explain it and others might want to help.
Right now there's nothing to work on here, at least nothing I understand.

@alex-dev
Copy link
Contributor Author

alex-dev commented Feb 3, 2020

DebugHandlersListener::configure()is therefore not called during a console command if the container was compiled by an HTTP request.

Error logs are not handled by configured logger (such as Monolog's) injected to DebugHandlersListener but by ErrorHandler default BootstrappingLogger.
That's a problem in a real world use case. I don't receive mail in prod when crons error out.

Everything else are other potential errors depending on their exact use cases.

@nicolas-grekas
Copy link
Member

DebugHandlersListener::configure()is therefore not called during a console command if the container was compiled by an HTTP request.

that's a good catch, this should be fixed!

@alex-dev
Copy link
Contributor Author

alex-dev commented Feb 4, 2020

No problem.. I'd just advise to state clearly in doc whether EventSubscriberInterface::getSubscribedEvents() should be compile-time or if it can be dynamic. Then I could fix code accordingly.

@xabbuh
Copy link
Member

xabbuh commented Feb 14, 2020

If you use the EventDispatcher component in framework-context, event listeners are wired during container compilation. From the code side that's the expected behaviour and there is nothing to be changed. If you feel like some docs could be improved, please feel free to submit a pull request. :) Therefore, I am closing here.

@nicolas-grekas
Copy link
Member

The issue with the registration of DebugHandlersListener is fixed in #35718

fabpot added a commit that referenced this issue Feb 15, 2020
…ess of the PHP_SAPI (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[HttpKernel] fix registering DebugHandlersListener regardless of the PHP_SAPI

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | #35579 (comment)
| License       | MIT
| Doc PR        | -

Commits
-------

3f995ac [HttpKernel] fix registering DebugHandlersListener regardless of the PHP_SAPI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants