Fixed ErrorException during email sending

Affected version
XenForo 2.2.4
Hey, we've been monitoring 3 individual errors appear frequently in the ACP Server Error Log:

Code:
ErrorException: Email to user@example.com failed: [E_WARNING] fwrite(): SSL: Broken pipe src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:240
Code:
Swift_TransportException: Email to user@example.com failed: Expected response code 250 but got code "451", with message "451 4.4.2 Timeout waiting for data from client. " src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:383
Code:
Email to user@example.com failed: Expected response code 250 but got code "", with message ""

Our XenForo installation is set-up to send emails to AWS using SMTP. (us-east-1, port 587, TLS encryption)

What appears to have solved this issue is manually closing the Swift_Transport by extending and modifying \XF\Mail\Mailer::send:
PHP:
try
{
    $sent = $transport->send($message, $failedRecipients);
    if (!$sent)
    {
        throw new \Swift_TransportException('Unable to send mail.');
    }
}
catch (\Throwable $e)
{
    if ($this->queue && $allowRetry)
    {
        $this->queue->queueForRetry($message, $queueEntry);
    }

    \XF::logException($e, false, "Email to {$toEmails} failed:");
}
finally
{
    $transport->stop();
}
Note that the finally block takes care of properly closing the transport.

This is obviously just a hot-fix on our side. I'm wondering if not closing the transport is intended, and if there is a proper solution we should be looking for.

Thanks!
 
Last edited:

gerryvz

Well-known member
Interesting. I have been receiving on very scattered occasions, EXACTLY the same messages, using Gmail as my engine. The errors tend to occur in clusters of three or four errors together, and I will go a couple or three weeks with no issues, then the issue crops up again.

I only remember seeing this in XF 2.2.x, not before.
 

XF Bug Bot

XenForo bug fixer bot
Staff member
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.5).

Change log:
When encountering a SMTP server error while sending email, attempt to establish a fresh connection before sending any further messages.
There may be a delay before changes are rolled out to the XenForo Community.
 

Mike

XenForo developer
Staff member
Worth mentioning that this actually ended up being a fair bit more complex because in the process of testing this (and I think this is something that gave me pause in the past when I tried something like this), I ran into a Swiftmailer bug that would essentially break the request if you tried to restart the transport. This is likely specific to the error being triggered, so it won't manifest in all cases.

I've reported that and included a temporary workaround for it within XF:

 

gerryvz

Well-known member
I still continue to get these same errors as the original poster showed, a couple or three times per week. I use gmail as a back-end sender. Doesn't happen every day, but regularly.

Also, and I have noticed this VERY consistently, the error ONLY occurs daily when the system sends out emails via the gmail engine, at 10:22 or 10:23 AM EDT. I do not receive errors at any other time of the day from email.

I am using the current (Patch 2) version of XF 2.2.6, but this has been happening consistently with all versions since at least 2.2.0 or 2.2.1.
 

FloV

Well-known member
Same here! I'm getting a couple of this per day as well:
  • ErrorException: Email to xxx failed: [E_WARNING] fwrite(): SSL: Broken pipe
  • src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:223
 
We are getting this. Any help fixing it would be great appreciated.
  • [E_NOTICE] fwrite(): write of 62 bytes failed with errno=32 Broken pipe
  • src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:231
 

Brogan

XenForo moderator
Staff member
We are getting this. Any help fixing it would be great appreciated.
  • [E_NOTICE] fwrite(): write of 62 bytes failed with errno=32 Broken pipe
  • src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:231
You will need to associate your forum user name with your license and then you can post in the customer support forums.
 
Top