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

Fix a PHP memory leak with SSL root certificates #12706

Merged
merged 1 commit into from Dec 11, 2017

Conversation

jackwakefield
Copy link
Contributor

@jackwakefield jackwakefield commented Sep 25, 2017

I've been running into an issue with requests to PHP-FPM increasing memory by ~100MB which doesn't get freed.

I ran strace on PHP-FPM and noticed many calls to map vendor/grpc/grpc/etc/roots.pem into memory, narrowed this down to grpc_ssl_roots_override_result and PHP_METHOD(ChannelCredentials, setDefaultRootsPem) mallocing default_pem_root_certs without freeing, so replaced this with grp_realloc and made sure to make a copy of the value in grpc_ssl_roots_override_result.

I based this on the C# extension

static grpc_ssl_roots_override_result override_ssl_roots_handler(

This appears to be related to #11632

@grpc-testing
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

14 similar comments
@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-testing
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-testing
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-testing
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-testing
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@stanley-cheung
Copy link
Contributor

Ok to test

@RyanGordon
Copy link

Does this need a mutex around it? Not entirely sure if this is correct but potentially multiple PHP requests can be setting the default credentials at any point. Before it wouldn't be an issue since the memory would just leak and still be valid but now that it is being re'alloced it could cause problems?

@skormel
Copy link

skormel commented Nov 27, 2017

@jackwakefield Your patch solve ours memory leaks problems.

I think this patch must be included on the main tree.

Thanks you very much.

@thelinuxfoundation
Copy link

Thank you for your pull request. Before we can look at your contribution, we need to ensure all contributors are covered by a Contributor License Agreement.

After the following items are addressed, please respond with a new comment here, and the automated system will re-verify.

Regards,
The Linux Foundation CLA GitHub bot

@jackwakefield
Copy link
Contributor Author

Signed.

@ZhouyihaiDing
Copy link
Contributor

ZhouyihaiDing commented Dec 1, 2017

Thank you for helping us find it.
The code looks good to me. I am going to make a test before merging it.
May I ask how you observe the memory usage? Using some php tools or read from the process directly?

@jackwakefield
Copy link
Contributor Author

I first picked it up in top after noticing performance degrading after each request, I then used strace as described here and noticed a large number of mmap calls mapping vendor/grpc/grpc/etc/roots.pem.

@ZhouyihaiDing
Copy link
Contributor

Jenkins, test this please

@ZhouyihaiDing
Copy link
Contributor

Sorry for the delay.
I run the tests in ubuntu and mac and it works well.
For the question about the lock, it's probably fine because setDefaultRootsPem is seldom called.
I think it's ready for merging after jenkins run the tests.
Thank you!

Copy link
Contributor

@ZhouyihaiDing ZhouyihaiDing left a comment

Choose a reason for hiding this comment

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

LGTM

@ZhouyihaiDing ZhouyihaiDing merged commit f9675bb into grpc:master Dec 11, 2017
nicolasnoble added a commit that referenced this pull request Jan 16, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet