php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9252 Bad database name leaves open connection
Submitted: 2001-02-14 05:03 UTC Modified: 2001-06-02 22:40 UTC
From: supporter-rwidmer at support dot zend dot com Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.0.4pl1 OS: Linux and FreeBSD 4
Private report: No CVE-ID: None
 [2001-02-14 05:03 UTC] supporter-rwidmer at support dot zend dot com
A Zend Help Desk customer (54) reported having an unreasonable number of connections to his database server in TIME_WAIT or CLOSE_WAIT state.  On closer inspection it was found that the database name passed to mysql_selectDB was invalid.  Correcting the database name appears to have hidden the problem again.

This became a major problem on his heavily loaded site because all the available Apache processes ended up waiting for database connections to close and made the server unavailable.  He is using Apache 1.13.14/PHP 4.04 on one server and MySQL 3.23.32 on
another.

I am able to reproduce the problem on PHP4.0.2PL1 on SuSE Linux 6.3 using MySQL 3.22.25.  I do get an error back from the mysql_selectDB() call, but the network connection to the database server stays open for a minute or so, in a TIME_WAIT state. Connecting to the same database server, with the same username and password using the mysql command line interpreter, then attempting to  use  an invalid database name does not result in hanging connections.

The following script will demonstrate the problem:

---------------------------------------
<?

mysql_connect( $host, $user, $password )
  or die( 'Unable to Connect - ' . mysql_error());

mysql_selectDB( 'invalid database name' )
  or die( 'Unable to Select - ' . mysql_error());

?>
All done
---------------------------------------

Set $host, $user, $password to a MySQL database on another machine, then hit this program a few times with your browser.  It ends properly in the die() for Unable to Select, but you will find that it leaves network connections to the database server open in TIME_WAIT state for about a minute after the script dies.  You can verify this with  

   netstat -na 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-02 22:40 UTC] sniper@php.net
Not PHP problem.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 14 02:01:31 2024 UTC