symfony / symfony

The Symfony PHP framework
https://symfony.com
MIT License
29.6k stars 9.42k forks source link

Sendmail transport runs out of memory #50486

Open rch77 opened 1 year ago

rch77 commented 1 year ago

Symfony version(s) affected

6.2 and other 6.*

Description

Trying to send a lot of Laravel 10 email notifications in loop, Sendmail transport runs out of memory: Allowed memory size of 5242880000 bytes exhausted (tried to allocate 2673869000 bytes)

at vendor/symfony/mailer/Transport/Smtp/Stream/AbstractStream.php:37 33▕ public function write(string $bytes, bool $debug = true): void 34▕ { 35▕ if ($debug) { 36▕ foreach (explode("\n", trim($bytes)) as $line) { ➜ 37▕ $this->debug .= sprintf("> %s\n", $line); 38▕ } 39▕ } 40▕ 41▕ $bytesToWrite = \strlen($bytes);

It seems the issue comes from vendor/symfony/mailer/Transport/SendmailTransport.php attempting to store in memory whole mail bodies as debugging information and not even clearing it when called in loop. E.g. SmtpTransport.php doesn't store the whole mail body in memory. I don't think production framework should do either by default.

How to reproduce

Call $user->notify($notification); in loop where notification uses MailMessage with /usr/sbin/sendmail -t -i -odq mailer.

Possible Solution

vendor/symfony/mailer/Transport/SendmailTransport.php @@ -113,7 +113,7 @@ $this->stream->setCommand($command); $this->stream->initialize(); foreach ($chunks as $chunk) {

Additional Context

No response

carsonbot commented 9 months ago

Hey, thanks for your report! There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

rch77 commented 9 months ago

Yes it's still relevant. The patch is still required to send larger amount of mail. The similar issue is with mailer/Transport/Smtp/SmtpTransport.php but the leak much smaller.

nicolas-grekas commented 9 months ago

Please send the patch as a PR it would gain more visibility.

carsonbot commented 3 months ago

Hey, thanks for your report! There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

carsonbot commented 2 months ago

Friendly ping? Should this still be open? I will close if I don't hear anything.

rch77 commented 2 months ago

It's still relevant