ecotoneframework / ecotone-dev

Ecotone Framework Development - This is Monorepo which contains all official public modules
https://docs.ecotone.tech
Other
37 stars 16 forks source link

Absolute path to the cache dir seems to be ... cached, using Symfony bundle #219

Closed someniatko closed 1 year ago

someniatko commented 1 year ago

Ecotone version(s) affected: 1.106.0

Description
Let's continue discussing cache-related stuff!

How to reproduce

  1. Set up a project in directory A with Symfony 6.3 + Ecotone + Ecotone Symfony Bundle. Set APP_ENV=prod, APP_DEBUG=false in ENV. Assume default Symfony cache configuration.
  2. Have some code in a Symfony controller which invokes Ecotone messaging in some way.
  3. Remove var/cache/prod dir.
  4. Execute php bin/console cache:clear, php bin/console cache:warmup.
  5. Set up a web server and make an HTTP request which would invoke your controller. All works fine.
  6. Move or copy your project directory somewhere else (alongside with var/cache/, vendor/ etc)
  7. Again, set up a web server and try making an HTTP request, which should now land in the new dir.

Now it won't work as in step 5, and you'll get a following exception:

ProxyManager\Exception\InvalidProxyDirectoryException
Provided directory "OLD-PROJECT-DIR/var/cache/prod/ecotone" does not exist

Possible Solution

I took the dir of a project I'm working on from its CI build (which includes vendor/, cache/ etc) and ran a webserver pointing to it locally on my computer. I've added the following to Ecotone\Messaging\Handler\Gateway\ProxyFactory::__construct():

    private function __construct(?string $cacheDirectoryPath)
    {
        $this->cacheDirectoryPath = $cacheDirectoryPath;
        echo "CACHE DIRECTORY PATH: {$this->cacheDirectoryPath}\n";
        debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
        echo "\n\n";
    }

Here's the output: https://gist.github.com/someniatko/bbaccca66eea61c48245a09b913db74b

It seems Ecotone actually creates the ProxyFactory twice, once for the cached version of MessagingSystemConfiguration, and the second for some other stuff. This cached MessagingSystemConfiguration I presume contains serialized PHP representation of the class, which also happens to contain the absolute path to the cache dir, which makes the project dir non-portable. UPD: it's part of ModuleReferenceSearchService::$moduleReferences['gatewayProxyConfiguration'] which is a ProxyFactory having cacheDirectoryPath.

Context
Symfony 6.3, APP_ENV=prod, APP_DEBUG=false

dgafka commented 1 year ago

@someniatko can you retest on 1.107.0?

someniatko commented 1 year ago

It seems you've fixed it, thank you!