Bug #20513 [Com]: Mail_smtp::send() doesn't close socket for smtp connection
| From: | jkingsnorth | Date: | Wed, 22 Mar 2017 09:59:44 +0000 |
| Subject: | Bug #20513 [Com]: Mail_smtp::send() doesn't close socket for smtp connection | ||
| References: | 1 | Groups: | php.pear.bugs |
| Request: | Send a blank email to pear-bugs+get-11378@lists.php.net to get a copy of this message | ||
Edit report at http://pear.php.net/bugs/bug.php?id=20513&edit=1
ID: 20513
Comment by: jkingsnorth
Reported By: john at johnkingsnorth dot co dot uk
Summary: Mail_smtp::send() doesn't close socket for smtp
connection
Status: Open
Type: Bug
Package: Mail
Package Version: 1.2.0
PHP Version: 5.4.33
New Comment:
Confirmed the issue. Unfortunately there seems to be a patch attached to
this that doesn't exist any more?
Previous Comments:
------------------------------------------------------------------------
[2015-03-09 11:20:09] e79ene
Added #patch bug:20513;patch:Fix-Bug-20513;revision:1425900009;.
------------------------------------------------------------------------
[2015-03-08 15:33:50] e79ene
Description:
------------
Mail::send() for smtp backend doesn't disconnect Net_Socket in
case of error.
I use Mail::send() with smtp backend to send mails from php
script on my FreeBSD server.
It works ok while there are no errors.
But if there's an error (E.g. SMTP authentication failure)
Mail::send() finishes and leaves tcp connection with smtp server
open.
My script tried to send thousands of mails and thus Mail::send()
opened thousands of socket connections and hit the system limit
of open files. As a result other services (such as database)
became unavailable too.
AFAIU the reason of the situation is in the source:
https://github.com/pear/Mail/blob/trunk/Mail/smtp.php
Mail_smtp::send() calls disconnect() in the end of function body
in case of success. However the function contains plenty of error
checks which perform return without call to disconnect().
Test script:
---------------
<?php
require_once('Mail.php');
$headers = array(
'From' => 'test@example.com',
'To' => 'test@example.com',
'Subject' => 'Text message subject',
);
$mailer = Mail::factory('smtp', array(
'host' => 'smtp.gmail.com',
'auth' => true,
'username' => 'fake@gmail.com',
'password' => 'the_password',
));
if (PEAR::isError($mailer))
die($mailer);
$res = $mailer->send($headers['to'], $headers, 'Test messge body');
if ($res === true)
echo "Mail sent.\n";
else
echo "send() failed.\n";
if (isset($mailer->_smtp)) {
echo "Socket status:\n";
print_r($mailer->_smtp->_socket->getStatus());
} else
echo "Connection closed.\n";
?>
Expected result:
----------------
send() failed.
Connection closed.
Actual result:
--------------
send() failed.
Socket status:
Array
(
[stream_type] => tcp_socket
[mode] => r+
[unread_bytes] => 0
[seekable] =>
[timed_out] =>
[blocked] => 1
[eof] =>
)
------------------------------------------------------------------------
--
Edit this bug report at http://pear.php.net/bugs/bug.php?id=20513&edit=1