From: ("")
Date:  23 Mar 2017 00:00:10 Hong Kong Time

[PEAR-BUG] Bug #20513 [Com]: Mail_smtp::send() doesn't close socket for smtp connection

NNTP-Posting-Host:  null

Edit report at

 ID:               20513
 Comment by:       eso at mail dot ru
 Reported By:      eso at mail dot ru
 Summary:          Mail_smtp::send() doesn't close socket for smtp
 Status:           Open
 Type:             Bug
 Package:          Mail
 Package Version:  1.2.0
 PHP Version:      5.4.33
 Roadmap Versions: 
 New Comment:

I don't know why the patch became unavailable. It definitely was here (2
years ago).
I've managed to find the file on my old broken HDD. Not sure if it is
still applicable.

Previous Comments:

[2017-03-22 11:54:58] e79ene

Added #patch bug:20513;patch:Fix-Bug-20513_again;revision:1490198098;.


[2017-03-22 05:42:29] jkingsnorth

Confirmed the issue. Unfortunately there seems to be a patch attached to
this that doesn't exist any more?


[2015-03-09 11:20:09] e79ene

Added #patch bug:20513;patch:Fix-Bug-20513;revision:1425900009;.


[2015-03-08 15:33:50] e79ene

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 
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:

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:
    'To' => '',
    'Subject' => 'Text message subject',

$mailer = Mail::factory('smtp', array(
    'host' => '',
    'auth' => true,
    'username' => '',
    'password' => 'the_password',

if (PEAR::isError($mailer))

$res = $mailer->send($headers['to'], $headers, 'Test messge body');

if ($res === true)
    echo "Mail sent.\n";
    echo "send() failed.\n";

if (isset($mailer->_smtp)) {
    echo "Socket status:\n";
} else
    echo "Connection closed.\n";

Expected result:
send() failed.
Connection closed.

Actual result:
send() failed.
Socket status:
    [stream_type] => tcp_socket
    [mode] => r+
    [unread_bytes] => 0
    [seekable] =>
    [timed_out] =>
    [blocked] => 1
    [eof] =>


Edit this bug report at