Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Symfony still loading secrets and decrypting even though .env.*.local (or .env.local.php) exists #52146

Closed
@719media

Description

@719media

Symfony version(s) affected

6.3.5 (tested again in 6.3.7, problem persists)

Description

When upgrading from Symfony 5.4 to Symfony 6.3, my production environment experienced severe CPU load (x1000).

I traced it down to an issue regarding the secrets file being 'decoded' on every CLI command. I am following best practices of secrets:decrypt-to-local so that the secrets are not required to be loaded on every request/command.

Troubleshooting futher, I narrowed down the problem to the inclusion of twig. Specifically, if I have a service that autowires twig (private Twig\Environment $twig), this problem arises.

How to reproduce

  1. composer create-project symfony/skeleton new_project/
  2. composer install
  3. composer require symfony/twig
  4. ./bin/console secrets:generate-keys
  5. ./bin/console secrets:set BLACK
  6. Create two commands, one of which extends twig, and the other which is configured to use the secret created in step 5 in the constructor
  7. Problem - command which extends twig needlessly runs script decrypt

To explicitly see the error at this point:

  1. Run composer install
  2. Run ./bin/console secrets:decrypt-to-local to create .env.dev.local, which should negate the need for secrets decryption
  3. Run ./bin/console app:test. Note lack of var_dump, even though a secret is being used in constructor. This is good!
  4. Run ./bin/console app:test-twig. var_dump! (No secrets even being used in constructor). This is bad!

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions