-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Memory allocated by stream_context_create not released when destroying stream_socket_server #10885
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
Meaning you've seen this issue actually crash the application? Or are you saying that it would hypothetically if it continued? |
@damianwadley It crashes the application with PHP Fatal error: Allowed memory size. You can see in the example in the original report that if you stick a |
`php_stream_context_set` already increases the refcount.
* PHP-8.1: Fix GH-10885: Leaking stream_socket_server context
* PHP-8.2: Fix GH-10885: Leaking stream_socket_server context
@iluuu1994 , I was going through this issue and was curious to know if this is applicable to :PHP 7. |
@HeenaBansal2009 , yes https://3v4l.org/XBaaP shows that it was observable all the way back to PHP5.2 and likely before (my testcase uses memory_get_usage() which didn't exists prior to that) |
Description
I have a long running PHP application that is creating stream_socket_server over time, the memory allocated by stream_context_create() is never released even after closing and destroying the stream_socket_server. A minimal reproduction is below (backlog is set to allocate more memory on each loop however even an empty array to stream_context_create shows this issue). Eventually the application will crash, this is more evident in memory constrained environments like container deployments.
I found an old PHP bugs report referencing this with stream_socket_client (https://bugs.php.net/bug.php?id=61371)
inhibition for deleting the context was too broad
and a really old one that says that stream_context_create() memory is never released https://bugs.php.net/bug.php?id=40257 but this is not documented.Output from memprof shows the allocated memory from stream_context_create()
Resulted in this output:
But I expected this output instead:
PHP Version
PHP 8.0.28 - PHP 8.2.4
Operating System
No response
The text was updated successfully, but these errors were encountered: