Skip to content

Fix generator memory leaks when interrupted during argument evaluation - #9756

Merged
arnaud-lb merged 1 commit into
php:PHP-8.0from
arnaud-lb:gh9750
Nov 4, 2022
Merged

Fix generator memory leaks when interrupted during argument evaluation#9756
arnaud-lb merged 1 commit into
php:PHP-8.0from
arnaud-lb:gh9750

Conversation

@arnaud-lb

Copy link
Copy Markdown
Member

Fixes #9750

Comment thread Zend/zend_execute.c Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicates cleanup_unfinished_calls(). I will look into ways to factor this out in an other PR.

@arnaud-lb arnaud-lb Oct 15, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is reused in #9810

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to simplify cleanup_unfinished_calls() in a way that it calls this function with a buffer, then frees all zvals on that buffer?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try this

Comment thread Zend/tests/generators/gh9750-008.phpt Outdated
Comment on lines 4 to 5

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8.0 calls D::__destructor: https://3v4l.org/32Ku7
8.1 does not because the constructor has not been called

@arnaud-lb
arnaud-lb marked this pull request as ready for review October 22, 2022 11:31
@arnaud-lb arnaud-lb changed the title [wip] Fix generator memory leaks when interrupted during argument evaluation Fix generator memory leaks when interrupted during argument evaluation Oct 22, 2022

@dstogov dstogov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first this looks terrible, but I don't see another solution and approve.

Actually, our "backup" GC started to walk over generators stacks, that made it similar to classic mark-and-sweep, but with higher overhead.

It would be interesting to see if this affects aerys performance.

@arnaud-lb

Copy link
Copy Markdown
Member Author

It would be interesting to see if this affects aerys performance

Indeed. I've tried running https://github.com/dbalabka/aerys-benchmark, and I've seen no differences before and after this PR.

@arnaud-lb
arnaud-lb merged commit 5d1f3e0 into php:PHP-8.0 Nov 4, 2022
arnaud-lb added a commit that referenced this pull request Nov 4, 2022
* PHP-8.0:
  [ci skip] NEWS
  Fix generator memory leaks when interrupted during argument evaluation (#9756)
arnaud-lb added a commit that referenced this pull request Nov 4, 2022
* PHP-8.1:
  [ci skip] NEWS
  [ci skip] NEWS
  Fix generator memory leaks when interrupted during argument evaluation (#9756)
arnaud-lb added a commit that referenced this pull request Nov 4, 2022
* PHP-8.2:
  [ci skip] NEWS
  [ci skip] NEWS
  [ci skip] NEWS
  Fix generator memory leaks when interrupted during argument evaluation (#9756)
adrian-enspired pushed a commit to adrian-enspired/php-src that referenced this pull request Aug 4, 2026
adrian-enspired pushed a commit to adrian-enspired/php-src that referenced this pull request Aug 4, 2026
* PHP-8.0:
  [ci skip] NEWS
  Fix generator memory leaks when interrupted during argument evaluation (php#9756)
adrian-enspired pushed a commit to adrian-enspired/php-src that referenced this pull request Aug 4, 2026
* PHP-8.1:
  [ci skip] NEWS
  [ci skip] NEWS
  Fix generator memory leaks when interrupted during argument evaluation (php#9756)
adrian-enspired pushed a commit to adrian-enspired/php-src that referenced this pull request Aug 4, 2026
* PHP-8.2:
  [ci skip] NEWS
  [ci skip] NEWS
  [ci skip] NEWS
  Fix generator memory leaks when interrupted during argument evaluation (php#9756)
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.

3 participants