-
Notifications
You must be signed in to change notification settings - Fork 7.9k
memory leak when using fopen with a stream wrapper #8548
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
Comments
The problem is that Note that even when this will be fixed, it's still not a good idea to repeatly register and unregister stream wrappers, because of potential resource ID depletion. |
@iluuu1994 Is there any possibility of backporting/releasing this in 8.0.*/8.1.*? Thanks! |
@olsavmic Since this is a rather theoretical and old leak I decided not to. Are you hitting this issue? |
Yes, pretty heavily due to symfony/http-client (symfony/symfony#46256). We have switched to guzzle client implementation which does not suffer from this issue so it's no longer critical for us but it's still an issue. I will suggest a singleton-like approach for the stream_wrapper_registrater call in the Symfony repository but I don't see into the internals of streams and linux resource ids. I'd assume that resource id is freed after unregistration but perhaps that's not the case? |
Oh, I wasn't aware Symfony actually unregisters the stream wrapper on every call. @nicolas-grekas Is unregistering really necessary or could Symfony check if the stream wrapper has already been registered? If not we should probably be able to back-port a5a89cc and c019421 since there aren't any public ABI breaks. @cmb69 Would that be ok for you? |
I'm not hard against back-porting, but I really think this should be fixed in userland; repeatedly registering and unregistering stream wrappers is not a good idea anyway, because of potential resource ID depletion. |
The goal of this code is to not leak anything in the global scope (aka not allow anyone but internal code to fopen() that kind of streams.) I didn't know this had any effect on resource ids. I'll look for changing this. |
All resources (regardless of kind) are internally stored in a hash table (see |
Sure, but what's the relationship with repeatedly registering and unregistering stream wrappers? |
php-src/main/streams/userspace.c Line 500 in 50bd8ba
|
PS: might be worth documenting this. |
Thanks for the hints. This should be fixed for Symfony in symfony/symfony#47143 |
…olas-grekas) This PR was merged into the 4.4 branch. Discussion ---------- [HttpClient] Fix memory leak when using StreamWrapper | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #46256 | License | MIT | Doc PR | - As hinted in php/php-src#8548 Commits ------- 16d0176 [HttpClient] Fix memory leak when using StreamWrapper
Description
The following code takes up a lot of memory and keeps increasing in a endless loop:
With a small change, the problem disappears:
The memory leak was described in the following ticket: symfony/symfony#46256
PHP Version
PHP 8.1.5 (cli)
Operating System
Ubuntu 20.04
The text was updated successfully, but these errors were encountered: