Bug #67596 [Opn->Nab]: mysqli connection in CLOSE_WAIT state if process is forked
| From: | johannes@php.net | Date: | Thu, 20 Nov 2014 13:05:30 +0000 |
| Subject: | Bug #67596 [Opn->Nab]: mysqli connection in CLOSE_WAIT state if process is forked | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-188709@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67596&edit=1
ID: 67596
Updated by: johannes@php.net
Reported by: christian dot p at maps-system dot com
Summary: mysqli connection in CLOSE_WAIT state if process is
forked
-Status: Open
+Status: Not a bug
Type: Bug
Package: MySQLi related
Operating System: Linux
PHP Version: 5.5.14
Block user comment: N
Private report: N
New Comment:
Yes that is expected. If PHP is forked all opened connections are shared, whoever finishes first
will close it leaving the other process in unexpected state. You have to close connection before
forking and create individual connections from each process afterwards.
Previous Comments:
------------------------------------------------------------------------
[2014-07-09 14:17:19] christian dot p at maps-system dot com
Description:
------------
When forking php process with exec, if a mysqli connection is already established, the child process
will retain this connection in a CLOSE_WAIT state, even if the parent destroys it afterwards.
It will retains one more CLOSE_WAIT connection per fork, leading to a "Unable to fork"
error, when the maximum nproc in ulimit is reached.
The linked script reproduces the problem.
It's possible to avoid the problem by calling $this->disconnect(); before forking.
I can understand that the child shares resources with its parent, but is it normal that the parent
cannot close the connection properly after the fork ?
Test script:
---------------
http://pastebin.com/5RmQutkk
Expected result:
----------------
Parent process should be able to close the mysqli connection.
Actual result:
--------------
Parent process close the mysqli connection without error, but a connection in CLOSE_WAIT state is
still present (lsof shows it).
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67596&edit=1