php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81029 SOAP HTTP socket not closing on object destruction
Submitted: 2021-05-11 10:32 UTC Modified: 2021-05-17 14:43 UTC
Votes:8
Avg. Score:4.8 ± 0.7
Reproduced:8 of 8 (100.0%)
Same Version:1 (12.5%)
Same OS:2 (25.0%)
From: kdonaldson at staff dot nexigen dot digital Assigned:
Status: Open Package: SOAP related
PHP Version: 7.4.19 OS: macOS and Cent OS 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
9 + 32 = ?
Subscribe to this entry?

 
 [2021-05-11 10:32 UTC] kdonaldson at staff dot nexigen dot digital
Description:
------------
If a SoapClient object is constructed without specifying the 'keep_alive' option to false, the socket never appears to be closed if it falls out of scope

The provided script should be able to reproduce this, you can check the open sockets by running the script like: "php /path/to/script.php &" and using the resulting PID on "lsof -a -p {pid}"

You should slowly see a list of TCP connections slowly build up over time similar to this:

php     4396 vagrant    3u  IPv4  53416      0t0     TCP homestead:57814->ec2-52-7-155-169.compute-1.amazonaws.com:https (ESTABLISHED)
php     4396 vagrant    4u  IPv4  53447      0t0     TCP homestead:57816->ec2-52-7-155-169.compute-1.amazonaws.com:https (ESTABLISHED)
php     4396 vagrant    5u  IPv4  54451      0t0     TCP homestead:57818->ec2-52-7-155-169.compute-1.amazonaws.com:https (ESTABLISHED)

If instead you were to add ['keep_alive' => false] as the options parameter on the SoapClient you'll see that the TCP connections don't appear to build up.

While I do understand the purpose of Keep Alive to keep a single connection open, I would assume this is still a bug as the SoapClient has gone out of scope and new SoapClient objects don't appear to reuse the existing connection and simply ignore it creating a new one.

Test script:
---------------
<?php

function call(int $number) {
    $client = new SoapClient('https://www.dataaccess.com/webservicesserver/NumberConversion.wso?WSDL');
    $response = $client->NumberToWords(['ubiNum' => $number]);
    return $response->NumberToWordsResult;
}

$numbers = array_fill(0, 10000, 1);

foreach ($numbers as $number) {
    call($number);
}

Expected result:
----------------
The socket to be closed when the SoapClient object falls out of scope or destructs

Actual result:
--------------
The socket stays open and contributes to the open file limit / file descriptor limit

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-05-11 11:27 UTC] cmb@php.net
It seems to me we're missing to undo the refcount increment[1]
when the object is destroyed.

[1] <https://github.com/php/php-src/blob/php-7.4.19/ext/soap/php_http.c#L523>
 [2021-05-17 14:43 UTC] nikic@php.net
@cmb: As it's stored in a property, shouldn't that happen automatically when the object (and thus also its properties) are destroyed?
 [2022-12-08 06:00 UTC] kimia dot salamsao9881 at gmail dot com
That was unexpected. 
(https://www.mynordstrom.ltd/)github.com
 [2022-12-15 11:06 UTC] johnsonsellen at gmail dot com
That was unpredicted. 
(https://dolgeneraldgme.com/)github.com
 [2022-12-21 08:54 UTC] jbriss at ebridge dot sk
The problem seems to be discussed here too:

https://github.com/googleads/googleads-php-lib/commit/17bf38ce7ba0a994f317ea78df40539f89a89789
 [2022-12-21 11:45 UTC] schamberumarcelo at gmail dot com
This closes the socket, but the web services engine does not recognize this as being closed and tries to reuse it, resulting in exceptions. The requests module leaves a connection open until it is garbage. when the response object is dropped, the file would be closed.  
(https://www.myccpay.me)github.com
 [2023-01-14 14:00 UTC] insidestrongs at gmail dot com
That was unimageable 
(https://www.mynstromy.com/)github.com
 [2023-02-09 16:08 UTC] meghaagarwalbaniya at gmail dot com
That was unpredicted. (https://mykohlscard.online/)github.com
 [2023-04-01 01:35 UTC] ammarloner at gmail dot com
This is an interesting topic.
 [2023-04-05 07:21 UTC] mikejohnarzona at gmail dot com
Travel Trend Blog is online platform sharing latest tour and travel about, destinaton, beaches, desert, jungle, snowfall destinaton etc. More info to visit: (https://traveltrendblog.com)github.com
 [2023-05-16 16:52 UTC] venile2040 at dekaps dot com
(https://mykohlscharge.online/)github.com
 [2023-05-21 12:14 UTC] johnsonsellen at gmail dot com
To avoid exceptions and ensure proper closure of connections when using the requests module in Python, remember to explicitly close the response object or utilize a context manager for automatic closure.
(https://getmyccpay.com)github.com
 [2023-07-22 14:50 UTC] forseobirdawade at gmail dot com
I am facing the same issue on site, do you know how to resolve it That was unpredicted. www.mykohlscard.pro
 [2023-08-10 15:37 UTC] andrewsauder at gmail dot com
I can duplicate the growing list of TCP connections bug in PHP version 8.1.22 NTS on Windows 11 Pro version 22H2. Is there a proposed solution?
 [2023-10-31 18:44 UTC] owork138 at gmail dot com
That was unpredicted. (www-upsers.us)github.com
 [2023-10-31 18:47 UTC] owork138 at gmail dot com
To avoid exceptions and ensure proper closure of connections when using the requests module in Python, remember to explicitly close the response object or utilize a context manager for automatic closure.
(www-upsers.us)github.com
 [2023-12-16 04:37 UTC] emmaturner at gmail dot com
To avoid exceptions and ensure proper closure of connections when using the requests module in Python, remember to explicitly close the response object or utilize a context manager for automatic closure.
[https://www-liteblue.us]github.com
 [2023-12-16 04:39 UTC] sincerelyjulie0 at gmail dot com
To avoid exceptions and ensure proper closure of connections when using the requests module in Python, remember to explicitly close the response object or utilize a context manager for automatic closure.
[https://www-liteblue.us](github.com)
 [2023-12-16 04:49 UTC] emmaturner at gmail dot com
To avoid exceptions and ensure proper closure of connections when using the requests module in Python, remember to explicitly close the response object or utilize a context manager for automatic closure.
[https://www-liteblue.us].[github.com]
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 02:01:30 2024 UTC