8000 bug #53157 [Mailer] Throw `TransportException` when unable to read fr… · fancyweb/symfony@4eb23d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4eb23d8

Browse files
bug symfony#53157 [Mailer] Throw TransportException when unable to read from socket (xdanik)
This PR was merged into the 5.4 branch. Discussion ---------- [Mailer] Throw `TransportException` when unable to read from socket | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? |no | Issues | None | License | MIT We are seeing error `fgets(): SSL: Connection reset by peer` multiple times a day from connection to Office 365 SMTP server (smtp.office365.com:587). It's certainly related to some kind of timeout as we are sending emails from long running queue dispatcher and error shows up only occasionally and never with the first message. We are not seeing this issue with any other SMTP server, but we have not tested much past smtp.mandrillapp.com and local MailHog. We have tried adjusting the `$pingThreshold` and `$restartThreshold` options, but without much success (well `$restartThreshold = 1` resolves the issue, but it also forces the transport to close connection after each message). Stack trace: ``` #0 /var/www/vendor/symfony/mailer/Transport/Smtp/Stream/AbstractStream.php(77): fgets(Resource(stream)) #1 /var/www/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php(315): Symfony\Component\Mailer\Transport\Smtp\Stream\AbstractStream->readLine() #2 /var/www/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php(181): Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->getFullResponse() #3 /var/www/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php(140): Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->executeCommand("RSET ", Array(1)) #4 /var/www/vendor/symfony/mailer/Mailer.php(45): Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->send(Object(Symfony\Component\Mime\Email), Null) symfony#5 (our queue dispatcher): Symfony\Component\Mailer\Mailer->send(Object(Symfony\Component\Mime\Email)) ``` App is running on PHP 8.0.28 on Debian Linux x64, Mailer v5.4.22. I would gladly written some tests for this, but I don't know how to simulate calls to low-level stream functions like fgets. Commits ------- 44d5b57 [Mailer] Throw TransportException when unable to read from socket
2 parents 2b7706a + 44d5b57 commit 4eb23d8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Symfony/Component/Mailer/Transport/Smtp/Stream/AbstractStream.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function readLine(): string
7474
return '';
7575
}
7676

77-
$line = fgets($this->out);
77+
$line = @fgets($this->out);
7878
if ('' === $line || false === $line) {
7979
$metas = stream_get_meta_data($this->out);
8080
if ($metas['timed_out']) {
@@ -83,6 +83,9 @@ public function readLine(): string
8383
if ($metas['eof']) {
8484
throw new TransportException(sprintf('Connection to "%s" has been closed unexpectedly.', $this->getReadConnectionDescription()));
8585
}
86+
if (false === $line) {
87+
throw new TransportException(sprintf('Unable to read from connection to "%s": ', $this->getReadConnectionDescription()).error_get_last()['message']);
88+
}
8689
}
8790

8891
$this->debug .= sprintf('< %s', $line);

0 commit comments

Comments
 (0)
0