-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Upgrading to symfony 6.4 from 6.3 causes major CPU spike (100x load) because of unnecessary secret decryption #53429
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
Can you create a small reproducer app? |
I mean you literally can follow the steps above, but here you go in repo form: You should run Then just run |
Any other information needed? For me, this is a 6.4 upgrade blocker, and it seems like it would be for anyone using symfony secrets? Thanks! |
I got as far as seeing that the introduction of |
I don't know if there is much we can do here. The container will always fall back to try reading from the vault if an environment variable is not found if I read the related correctly. If you define the |
@xabbuh Yes, according to what I was testing, it works. Honestly, I can't even figure out what the "default" of APP_RUNTIME_MODE is SUPPOSED to be in order to even set it the same. I guess that's the problem here. If you do a regular, default install of symfony 6.4 or 7.x, and add any secret at all, you instantly suffer really bad performance. To me, that should be unacceptable by any standard. So, what solutions are there? Well, I'm too ignorant of symfony standards to know for sure, but some ideas:
Again, I'm not very familiar with this part of symfony, so I don't know the reasoning behind all the choices. I just know that, as is, it definitely seems wrong to me. |
This should be fixed by #53631; can you please give it a try? |
…s when only a subset is needed (nicolas-grekas) This PR was merged into the 6.4 branch. Discussion ---------- [DependencyInjection] Fix loading all env vars from secrets when only a subset is needed | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #53429 | License | MIT As spotted in the linked issue, we have a significant performance issue when loading env vars. The issue is that when one env var is needed but not defined, we still decrypt all existing env vars. This also means we have a scalability issue when the number of env vars increases. Since this happens usually on every single requests, this can burn the CPU. The solution implemented in this PR is to use lazy strings to load env vars so that we don't decrypt them unless they are actually needed. Commits ------- 1d6f795 [DependencyInjection] Fix loading all env vars from secrets when only a subset is needed
Symfony version(s) affected
6.4.x, 7.x
Description
Secrets are being decrypted even though .env.local.* exists. Same symptom as #52146, but for different reasons.
How to reproduce
Can reproduce it easily by following the same steps, only actually more easily reproducible:
config/secrets/dev/dev.decrypt.private.php
(this file should not be used because the secrets have been decrypted to local)./bin/console
and note that the error_log or var_dump is echo to screen. This should not happen.Possible Solution
It appears related to the introduction of APP_RUNTIME_MODE. If you explicitly define this in .env, you can avoid the secret decrypting. However, if you want the default behavior of APP_RUNTIME_MODE to be null, so that runtime_mode is dynamically calculated, this gets a little confusing on how to accomplish this. Shouldn't be required to understand this parameter just to get secrets to work properly.
Additional Context
Seems like secret decryption is rather "fragile", perhaps it should be made less brittle in that any ENV var not found will force the entire secrets list to be decrypted...
The text was updated successfully, but these errors were encountered: