Skip to content

[TASK] Collect garbage cycles only between tests - #900

Merged
d-g-codappix merged 1 commit into
mainfrom
gc-collect-cycles
Nov 24, 2026
Merged

d-g-codappix merged 1 commit into
mainfrom
gc-collect-cycles

Conversation

@d-g-codappix

Copy link
Copy Markdown
Collaborator

Resolves: #899

The functional tests crashed randomly with a segmentation fault (exit code 139) on PHP 8.2, e.g. in #898 (about every second run, locally and in CI).

Cause (core dump and valgrind with USE_ZEND_ALLOC=0): during an outer serialize() the garbage collector destroys an Extbase\Reflection\ReflectionService of an earlier test instance. Its destructor writes the class schemata to the cache and calls serialize() again; the nested call resizes and frees the reference table of the outer call, which reads it afterwards.

  • New PHPUnit extension Tests/PhpUnit/GarbageCollectionExtension, registered in Build/phpunit.xml.dist: disables the automatic garbage collection and calls gc_collect_cycles() after the set up of each test and after each test.
  • gc_collect_cycles() also collects with the automatic garbage collection disabled (checked on PHP 8.2, 8.3 and 8.4), the memory usage of the functional tests stays the same (305 MB).

Verified with the code of #898 on PHP 8.2: without the extension 3 of 5 runs crashed, with it 4 of 4 runs passed (288 tests).

The functional tests crashed randomly with a segmentation fault on
PHP 8.2. Objects of earlier test instances, e.g. the Extbase
ReflectionService, are destroyed by the garbage collector. The
destructor of the ReflectionService writes the class schemata to the
cache, which calls serialize(). If the garbage collector runs while
another serialize() is in progress, the nested serialize() frees memory
the outer one still uses.

A PHPUnit extension disables the automatic garbage collection and
collects the cycles after the set up of each test and after each test.

Resolves: #899

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@d-g-codappix
d-g-codappix merged commit 0dca2f3 into main Nov 24, 2026
25 checks passed
@d-g-codappix
d-g-codappix deleted the gc-collect-cycles branch November 24, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Functional tests crash randomly with a segmentation fault on PHP 8.2

1 participant