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

Skip to content

[DependencyInjection] env vars are not reset upon kernel.reset #59128

Closed
@faizanakram99

Description

@faizanakram99

Symfony version(s) affected

7.1.0

Description

#54666 was supposed to reset env vars upon kernel.reset but seems it doesn't work as intended, it probably works for web environments with booted kernels like php-pm or frankenphp worker mode as container is reset for them on each kernel boot but not for messenger workers. Currently there are two issues with it.

  1. EnvVarProcessor is not tagged with kernel.reset
  2. Env vars are cached higher up in stack in Container (service_container) and they are never reset.

See #54666 (comment)

How to reproduce

Reproducer isn't needed, the description is enough to explain the issue.

Possible Solution

First issue can be fixed by adding ->tag('kernel.reset', ['method' => 'reset']) here

Second issue, I'm not sure, maybe we should get rid of services resetter altogether and just reboot kernel (edit: bad idea as pointed out by @stof in following comment). Alternatively, add service_container to services_resetter but just reset envCache (and not other services). It would require another public method other than reset in container class and tagging it with kernel.reset and use that method as "resetMethod". Instead of tagging service_container with kernel.reset, we could simply call that public method from EnvVarProcessor::reset()

Additional Context

Resetting env vars is necessary to be able to run symfony messenger workers for a multi tenant application (single web server multiple databases) where each message is identified with a tenant stamp and depending upon the tenant id, its env var needs are loaded like database_url, filesystem path etc. Also it is similar to web model that way, each message is handled without causing side effects (in isolation).

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