Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Sendmail transport runs out of memory #50486

Copy link
Copy link
Closed
@rch77

Description

@rch77
Issue body actions

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) {
-            $this->stream->write($chunk);
+            $this->stream->write($chunk, false);
         }
         $this->stream->flush();
         $this->stream->terminate();

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.