Repository navigation
fix(tia): stop ReadCapture from keeping a wrapper per filesystem call - #2057
Merged
MrPunyapal merged 3 commits intoNov 21, 2026
Merged
Conversation
stream_wrapper_restore() takes a user wrapper out of the wrapper table but does not free it, so every filesystem call made while a test records kept one until the process ended. Unregistering it first frees it.
A test can unregister file:// itself. stream_wrapper_unregister() then warns, where stream_wrapper_restore() alone did not, so check first. Also run the per-test memory check over 5,000 tests and update the snapshot and parallel totals for the new tests.
Member
|
Please use |
Contributor
Author
|
Done in It still catches the leak: about 1.4 to 1.6 MB growth without the fix, and 16 bytes with it, including on PHP 8.6 with OPcache on for the CLI. I also updated the PR description and removed the unrelated PHP 8.6 caveat. |
MrPunyapal
approved these changes
Nov 21, 2026
MrPunyapal
left a comment
Member
There was a problem hiding this comment.
Verified the updated memory regression on PHP 8.6 with CLI OPcache enabled. Integration and CI passed.
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What:
Description:
With
--tiarecording, memory grows with every filesystem call a test makes, and a little more for every test. On a long suite this adds up (#2035).The cause is in PHP, not in the recorder.
ReadCapturesteps aside around each filesystem call and at the end of each test by callingstream_wrapper_restore('file'), then registers itself again.stream_wrapper_restore()drops the user wrapper from the table but never frees it, so every call leaves one wrapper behind until the process ends.stream_wrapper_unregister()does free it.This PR makes
disable()callstream_wrapper_unregister('file')first, then restore or re-register the previous wrapper as before. The unregister is skipped whenfile://is already gone, so a test that unregistered it itself does not raise a notice.Four tests in
tests/Unit/Plugins/Tia/ReadCapture.php:fopen()andfclose()calls while a test records keep under 100 KB.file://gets no notice, and the plain wrapper is back after.file://gets no notice, and the plain wrapper is back after.On the current 5.x code the first three fail. The fourth fails on the fix without the guard.
tests/.snapshots/success.txtwas regenerated withREBUILD_SNAPSHOTS=true, and the totals intests/Visual/Parallel.phpcome from a real parallel run.Measured on PHP 8.4, 8.5 and 8.6 RC7:
fopen()andfclose()pairs while recording: about 1.6 MB before on PHP 8.4 and 8.5 (1.4 MB on 8.6), and 16 bytes after, including 8.6 with OPcache on for the CLI.On a Laravel 13 app with 401 tests (PHP 8.4, pcov):
--tia --fresh: +40.22 MB before, +34.41 MB after, +34.48 MB with read capture turned off.--tia --fresh --parallel --processes=4: the workers grow 49.29 MB in total before and 43.4 to 43.6 MB after.--parallel.With OPcache on for the CLI, files included through the wrapper still load and are cached. An exception thrown during a filesystem call still leaves
ReadCaptureregistered, and the right wrapper is back at the end of the test.This does not change the separate failing test reported in #2035, or #2039 and #2056. If #2039 lands and
ReadCapturestops swapping wrappers per call, this fix is no longer needed.Related:
Fixes the memory growth in #2035