-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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] Memory leaking when sending many emails #45211
Comments
Here is something similar related to Message Logger listener: #37712 |
The I'm wondering why MessageLoggerListener is registered in prod. It is a debugging tool |
@stof good point. |
@alexkingdom Did you manage to find out why the service is registered in the prod environment? |
@xabbuh actually no. I just use my fix. |
Let's close here for now then until we are able to reproduce. |
I am seeing the same problem. My logs (each mail sending iteration), with memory usage: Without calling
After running all the code except for When calling
We have a peak usage of 55,340,568 and that keeps going up, each email, until it hits the memory limit and is killed. When I call
However there's still some creep; I'll run with this in production and see how it fares under proper loads. This is my monolog config, should it be relevant:
|
After 18 hours since deploying the code with |
Well, if you use a fingers_crossed handler in a long running process, it will indeed leak memory (as it collects logs). Resetting stateful services between the processing of each message in a worker is the expected usage. |
@stof - thanks for the response. Looks like fingers_crossed is the default recommendation from the monolog recipe, which is why I would have it configured: Should something be updated there then? |
Well, for the webserver, this is the sane default. And for workers, this can be a good config as well if you reset stateful services properly between messages. |
Symfony version(s) affected
5.3, 5.4
Description
This problem I had before (https://stackoverflow.com/questions/67248353/symfony-5-memory-leaking-when-send-multiple-emails-through-mailer) but it fixed after upgrading Symfony.
Now I started to have again problems related mailer when sending many emails through command.
Code inside
execute
method of command:And here is the piece of method
sendNewsletter
:If to comment
$this->mailer->send($email)
no problem at all. For testing I'm using dsn:null://null
Upgrading / downgrading of symfony not helped me.
I'm using right now Symfony 5.4 and php 7.4
Note: Memory limit that is used for command is 512 MB.
How to reproduce
Just create a command send many emails and on each sent email track the memory peak and you will see how it's increasing.
Possible Solution
After investigation and debugging I found that so called MessageLoggerListener (
vendor/symfony/mailer/EventListener/MessageLoggerListener.php
) is collecting logs but don't reset the logs.So I decorated this listener and just reset after ever 50 events. I don't like this solution so for this reason I wrote here, maybe there is better solution.
Here is the code:
And service.yml:
Additional Context
No response
The text was updated successfully, but these errors were encountered: