History log of /PHP-8.3/Zend/tests/gh13670_002.phpt (Results 1 – 2 of 2)
Revision Date Author Comments
# bb6b659a 26-Mar-2024 Arnaud Le Blanc

Tests are not repeatable

gc_threshold is inherited accross requests, so the tests fail when repeating


# c13794cd 25-Mar-2024 Arnaud Le Blanc

Adjust GC threshold if num_roots is higher than gc_threshold after collection (#13758)

This fixes an edge case causing the GC to be triggered repeatedly.

Destructors might add poten

Adjust GC threshold if num_roots is higher than gc_threshold after collection (#13758)

This fixes an edge case causing the GC to be triggered repeatedly.

Destructors might add potential garbage to the buffer, so it may happen that num_root it higher than gc_threshold after collection, thus triggering a GC run almost immediately. This can happen by touching enough objects in a destructor, e.g. by iterating over an array. If this happens again in the new run, and the threshold is not updated, the GC may be triggered again.

The edge case requires specific conditions to be triggered and it must happen rarely in practice:

* At least GC_THRESHOLD_TRIGGER (100) objects must be collected during each run for the threshold to not be updated
* At least GC_G(gc_threshold) (initially 10k) objects must be touched (decref'ed to n>0) by any destructor during each run to fill the buffer

The fix is to increase the threshold if GC_G(num_roots) >= GC_G(gc_threshold) after GC. The threshold eventually reaches a point at which the second condition is not met anymore.

The included tests trigger more than 200 GC runs before the fix, and 2 after the fix (dtors always trigger a second run).

A related issue is that zend_gc_check_root_tmpvars() may add potential garbage before the threshold is adjusted, which may trigger GC and exhaust the stack. This is fixed by setting GC_G(active)=1 around zend_gc_check_root_tmpvars().

show more ...