php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67596 mysqli connection in CLOSE_WAIT state if process is forked
Submitted: 2014-07-09 14:17 UTC Modified: 2014-11-20 13:05 UTC
From: christian dot p at maps-system dot com Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 5.5.14 OS: Linux
Private report: No CVE-ID: None
 [2014-07-09 14:17 UTC] 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).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-11-20 13:05 UTC] johannes@php.net
-Status: Open +Status: Not a bug
 [2014-11-20 13:05 UTC] johannes@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 09:01:28 2024 UTC