Skip to content

Commit 138dbf1

Browse files
committed
minor #16690 [Messenger] Services that need reset must implement ResetInterface (volendavidov)
This PR was squashed before being merged into the 6.1 branch. Discussion ---------- [Messenger] Services that need reset must implement ResetInterface Closes #16688 Commits ------- 0203dfb [Messenger] Services that need reset must implement ResetInterface
2 parents 8d0a9d9 + 0203dfb commit 138dbf1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

messenger.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,11 +707,16 @@ you can decide to not take care of services that may leak memory.
707707

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

712713
However, certain Symfony services, such as the Monolog
713714
:ref:`fingers crossed handler <logging-handler-fingers_crossed>`, leak by design.
714715
That's why Symfony automatically resets the service container between two messages.
716+
If a service is not stateless and you want to reset its properties after each message, then
717+
the service must implement :class:`Symfony\\Contracts\\Service\\ResetInterface` where you can reset the
718+
properties in the ``reset()`` method.
719+
715720
If you don't want to reset the container, add the ``--no-reset`` option when
716721
running the ``messenger:consume`` command.
717722

0 commit comments

Comments
 (0)