Skip to content

[Messenger] Services that need reset must implement ResetInterface #16690

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

Merged
merged 1 commit into from
Apr 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion messenger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -707,11 +707,16 @@ you can decide to not take care of services that may leak memory.

On the other hand, workers usually sequentially process messages in long-running CLI processes, which don't
finish after processing a single message. That's why you must be careful about service
states to prevent information and/or memory leakage.
states to prevent information and/or memory leakage as Symfony will inject the same instance of a
service, preserving the internal state of the service between messages.

However, certain Symfony services, such as the Monolog
:ref:`fingers crossed handler <logging-handler-fingers_crossed>`, leak by design.
That's why Symfony automatically resets the service container between two messages.
If a service is not stateless and you want to reset its properties after each message, then
the service must implement :class:`Symfony\\Contracts\\Service\\ResetInterface` where you can reset the
properties in the ``reset()`` method.

If you don't want to reset the container, add the ``--no-reset`` option when
running the ``messenger:consume`` command.

Expand Down