Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.4.1

Bug #20513 Mail_smtp::send() doesn't close socket for smtp connection
Submitted: 2015-03-08 19:33 UTC
From: e79ene Assigned: ashnazg
Status: Closed Package: Mail (version 1.2.0)
PHP Version: 5.4.33 OS:
Roadmaps: (Not assigned)    
Subscription  


 [2015-03-08 19:33 UTC] e79ene (Eugene Ostrovsky)
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] => )

Comments

 [2015-03-09 15:20 UTC] e79ene (Eugene Ostrovsky)
 [2017-03-22 09:42 UTC] jkingsnorth (John Kingsnorth)
Confirmed the issue. Unfortunately there seems to be a patch attached to this that doesn't exist any more?
 [2017-03-22 15:54 UTC] e79ene (Eugene Ostrovsky)
 [2017-03-22 16:00 UTC] e79ene (Eugene Ostrovsky)
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.
 [2017-04-11 14:01 UTC] ashnazg (Chuck Burgess)
-Status: Open +Status: Assigned -Assigned To: +Assigned To: ashnazg
PR issued based on this patch -- https://github.com/pear/Mail/pull/13 (original patch files were lost by a disk failure in ?2016?)
 [2017-04-11 14:31 UTC] ashnazg (Chuck Burgess)
-Status: Assigned +Status: Closed
Fix applied, look for it in upcoming release. Thanks for the patch, e79ene!