Garbage collection stops after exception in SoapClient
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code:
<?php
class A
{
public $b;
}
class B
{
public $a;
}
function buildCycle()
{
$a = new A();
$b = new B();
$a->b = $b;
$b->a = $a;
}
function failySoapCall()
{
try {
new SoapClient('https://nowhere.inexistent.space/?WSDL');
}
catch (Exception) {
echo "Soap call failed\n";
}
}
function gc()
{
gc_collect_cycles();
echo "GC Runs: " . gc_status()['runs'] . "\n";
}
buildCycle();
gc();
buildCycle();
gc();
buildCycle();
gc();
failySoapCall();
buildCycle();
gc();
buildCycle();
gc();
buildCycle();
gc();
Resulted in this output:
GC Runs: 1
GC Runs: 2
GC Runs: 3
Soap call failed
GC Runs: 3
GC Runs: 3
GC Runs: 3
But I expected this output instead:
GC Runs: 1
GC Runs: 2
GC Runs: 3
Soap call failed
GC Runs: 4
GC Runs: 5
GC Runs: 6
The SOAP exception apparently stops the garbage collector. I experienced this problem with a large, long running process. Its memory usage is intensive but stable. Until it encounters a SOAP exception: its memory usage skyrockets, and gc_status() reports that no more gc run is done.
PHP Version
PHP 8.1.13
Operating System
Alpine 3.16
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the provided PHP reproduction with SoapClient, gc_collect_cycles(), and gc_status() on PHP 8.1.13 and Alpine 3.16. Start by tracing the exception path and its interaction with cyclic garbage collection. Done means garbage-collection runs continue after the failed SOAP call and the reported cycle counts match the expected output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100