php / php/php-src

Garbage collection stops after exception in SoapClient

Open
#10,026 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Extension: soap Status: Verified
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.