-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
[Mailer] Redundant MessageEvent dispatch #34972
Comments
I confirm this bug. In tests it make |
One of the MessageEvent has the $queued property set to true so they are "different". Problem is that the MessageLoggerListener should check this attribute before adding it to the list. This issue is applicable on other listener. If we take the Symfony\Component\Mailer\EventListener\MessageListener the event will be process everytime, causing the renderer to be call twice (for example the Symfony\Bridge\Twig\Mime\BodyRenderer). I was trying to ignore some event form the listener base on $event->isQueued() but there is a problem of object reference. The message from the event and the message for the envelope is not the same on the the $event->isQueued() === false, which is not the case on the first event. This is causing problem if we add a recipient on the message since the AbtractTransport will check the recipient from the envelope which will have a reference on the wrong message. |
As mentioned already, the 2 events are different. One if for the message that is queued and the other is from when the message is sent. #36445 fixes the web profiler to make things clearer and less confusing. Regarding test assertions, I've just tested and it works: $this->assertEmailCount(1);
$this->assertQueuedEmailCount(1); |
…nd sent emails (fabpot) This PR was merged into the 5.1-dev branch. Discussion ---------- [WebProfilerBundle] Make a difference between queued and sent emails | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes-ish | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Refs #34972 <!-- prefix each issue number with "Fix #", if any --> | License | MIT | Doc PR | n/a The current profiler panel for Mailer is confusing when emails are sent synchronously. Before:  After:  The new version makes a difference between queued and sent messages. The goes goes for the web debug toolbar. I've also fixed an HTML markup issue and made the display more compact. Commits ------- 0ee98a1 [WebProfilerBundle] Make a difference between queued and sent emails
Yes but the problem is that they are handle twice by the Symfony\Bridge\Twig\Mime\BodyRenderer the $event->isQueued() is never checked... So probably there is a lot of listener that process both event, that should not be the case. Having two different event would solve the issue, otherwise all listener need to be double checked and an issue open directly in each component. |
A side-effect of this is that a I believe the setup to repeat is this: A) Install mailer AND Messenger Cheers! |
@weaverryan I don't get the issue. The message is cloned, so we are indeed rendering the email twice, but that's from 2 different instances (which means that I will close the issue again as there is no "bug" here). But, back to Encore. Does that mean that you cannot call Wait, I've just tried to find out. So, if you call It means that you can only call |
But why would we need to render the email twice ? It doesn't make any sens... I understand that the even is dipatched twice (with the isQueued returning true on the first event) but the rendering will be executed twice once for the queued email (that is not sent) and again when the email is sent (via the messenger). Should be open a issue in the twiw-bridge component to make sure the email is justrendered when "isQueued !== false" ? |
The queued message should be rendered for the profiler. I don't see any issue here. |
Make sens for the profiler but this behaviour should not be triggered when profiler is not aviable (aka in production) but it will |
The profiler was just an example. Tests is another one. In any case, we want to run all listeners on both messages to get the same end result (the fact that the email is sent or not is not relevant here). You might have some listeners that could do things differently depending on the queue status though, but I don't think this should be the case for the built-in ones. |
Symfony version(s) affected: 4.4.1
Description
When only one email is sent in a Symfony application having also the Messenger component, two MessageEvents are actually dispatched.
Not sure if it is a bug or it is done on purpose, but it brings some confusion in the Web profiler where it shows a queued email in a "[main]" transport :
Seen also in functional tests using non-mocked, by default injected dependencies and checking sent emails count through dispatched events.
How to reproduce
In a Symfony 4.4 application in development mode (web profiler and debug activated), having Messenger component, and an implemented Mailer.
When an email is sent and Mailer is configured for 1 dsn, it should show 2 emails in web profiler, one sent by the actual configured dsn, and one queued in a "[main]" transport.
Possible Solution
Remove the MessageEvent dispatch in
Symfony\Component\Mailer\Mailer:send
and keep only the Messenger's MessageBus dispatch.Additional context
The 2 MessageEvents come from :
Symfony\Component\Mailer\Transport\AbstractTransport:send
Symfony\Component\Mailer\Mailer:send
- if MessageBus is not null (the dispatched transport in MessageEvent is an instance ofSymfony\Component\Mailer\Transport\Transports
)The text was updated successfully, but these errors were encountered: