Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leaks due to str_pad() in yii\base\ErrorHandler::register() #19738

Closed
maximal opened this issue Jan 11, 2023 · 4 comments
Closed

Memory leaks due to str_pad() in yii\base\ErrorHandler::register() #19738

maximal opened this issue Jan 11, 2023 · 4 comments

Comments

@maximal
Copy link
Contributor

maximal commented Jan 11, 2023

Hi there!

I’m using Yii2 with RoadRunner through charlesportwoodii/yii2-psr7-bridge package (https://github.com/charlesportwoodii/yii2-psr7-bridge).

I had set memprof extension (https://github.com/arnaud-lb/php-memory-profiler/) to dump memory profile every 1000 processed requests and got some interesting results:

image

Almost all memory leaks are caused by yii\base\ErrorHandler::register() method which internally uses str_pad() to reserve some merory for fatal error handling:

image

It works perfect in classic (but not performant) PHP short-living application approach but behaves badly in long-running approach where one application instance responses to many requests.

Any ideas on how we can fix this?

What steps will reproduce the problem?

  1. Use RoadRunner through charlesportwoodii/yii2-psr7-bridge.
  2. Set memprof with some memprof_enable() and memprof_dump_callgrind() calls.
  3. Open callgrind profile file in KCachegrind.

What is the expected result?

yii\base\ErrorHandler::register() reserves memory for fatal exception handler only once and not for every request. (?)

What do you get instead?

yii\base\ErrorHandler::register() reserves memory for fatal exception handler for every request.

Additional info

Q A
Yii version 2.0.47
PHP version 8.2
Operating system Debian 11.6 ×64
@samdark
Copy link
Member

samdark commented Jan 13, 2023

The memory reserved should be freed if the object is destroyed. I guess the bridge package could solve it by killing the app instance and de-registering error handler.

@samdark
Copy link
Member

samdark commented Jan 13, 2023

Anyway, that's not the framework issue but likely an issue of the bridge package. If not, please feel free to submit a pull request with a fix.

@samdark samdark closed this as completed Jan 13, 2023
@maximal
Copy link
Contributor Author

maximal commented Jan 13, 2023

@samdark, I think, the whole idea of RoadRunner-based approach is not to kill an application instance with every request, so that the framework can process long-living request-response loop. And, I suppose, the framework could handle its memory consumption here.

Anyway, I guess, I should open an issue in that bridge repository. Thanks for the reply!

@cebe
Copy link
Member

cebe commented Jan 19, 2023

Not sure how RoadRunner handles PHP memory limit but if memory limit exception handling works without the trick we use here you can set the size of errorHandling reserve to 0.

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

No branches or pull requests

3 participants