Skip to content

[Mailer] Fix Sendmail memory leak #59256

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

Merged
merged 1 commit into from
Jan 7, 2025
Merged

Conversation

rch7
Copy link
Contributor

@rch7 rch7 commented Dec 18, 2024

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #50486
License MIT

Previous PR: #59239

Fixes issue #50486 (Sendmail transport runs out of memory).

  • I have removed unrelated changes that somehow got in the previous attempt of pull request because of wrong base version.
  • As for the "metrics about the memory leak itself" - it is in the issue 50486. When write(), which is defined in vendor/symfony/mailer/Transport/Smtp/Stream/AbstractStream.php, is called without $debug parameter, it's true by default, and $this->debug gets appended all the email body data incrementally.
    So for example if you have loop sending personalized emails to 200,000 subscribers 20 kB each, $this->debug becomes 4 GB, plus overhead, and the script runs out of resources.
    The fix eliminates the problem.

@alexislefebvre

This comment has been minimized.

@welcoMattic welcoMattic changed the title fix_50486 - memory leak [Mailer] Fix Sendmail memory leak Dec 19, 2024
@GromNaN GromNaN added the Mailer label Dec 20, 2024
@@ -114,7 +114,7 @@ protected function doSend(SentMessage $message): void
$this->stream->setCommand($command);
$this->stream->initialize();
foreach ($chunks as $chunk) {
$this->stream->write($chunk);
$this->stream->write($chunk, false);
Copy link
Member

@nicolas-grekas nicolas-grekas Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For next reviewers: this sets the debug flag, so that the stream instance doesn't keep a string copy of what was written. This debug info is not accessible anywhere anyway.
That's similar to:
https://github.com/rch7/symfony/blob/c74e2a3d7e1df817b2bea7d8f6a8fc3373c445bb/src/Symfony/Component/Mailer/Transport/Smtp/SmtpTransport.php#L222

@nicolas-grekas
Copy link
Member

Thank you @rch7.

@nicolas-grekas nicolas-grekas merged commit 8d5be07 into symfony:6.4 Jan 7, 2025
10 of 11 checks passed
This was referenced Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants