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

cached proxies are still regenerated on fly even if dumped #232

Closed someniatko closed 1 year ago

someniatko commented 1 year ago

Ecotone version(s) affected: 1.108.1

Description
Continuation of https://github.com/ecotoneframework/ecotone-dev/issues/217

Now cache:warmup Symfony command properly generates proxy classes in <cache-dir>/ecotone, however they are still generated on fly.

How to reproduce

  1. Set up a Symfony project with Ecotone.
  2. Make <cache-dir>/ecotone readonly
  3. Comment or remove Assert::isTrue(is_writable($cacheDirectoryPath), ...) in MessagingSystemConfiguration. By the way, this check prevents me from having a readonly cache dir, which I would like to have after I dumped all proxies via cache:warmup. Dunno what to do about it, I suggest just removing it altogether - if the cache dir is not writable at the moment of writing a proxy class, it will tell you anyway.
  4. Launch php bin/console list or php bin/console ecotone:list.

You'll get an error Cannot rename "/tmp/ProxyManagerGeneratedProxy__PM__EcotoneMessagingGatewayConsole....

Possible Solution
See https://github.com/Ocramius/ProxyManager/blob/2.15.x/docs/tuning-for-production.md

Basically we have to register the proxy autoloader before attempting to use proxies. Otherwise they are regenerated each time as now.

I added spl_autoload_register($this->getConfiguration()->getProxyAutoloader()) to ProxyFactory::createProxyClassWithAdapter() as a proof of concept, and proxies stopped being regenerated each time. And it worked with the readonly cache dir (I want to have fully immutable project dir).

I remember about PRs I have agreed to do in the earlier discussions BTW :D

dgafka commented 1 year ago

Hey @someniatko,

I added spl_autoload_register($this->getConfiguration()->getProxyAutoloader()) to ProxyFactory::createProxyClassWithAdapter() as a proof of concept, and proxies stopped being regenerated each time. And it worked with the readonly cache dir (I want to have fully immutable project dir).

The autoloader is done in MessagingSystemConfiguration now. Can you provide PR that will move it to ProxyFactory and for checking writing only in case we dump the config?

I remember about PRs I have agreed to do in the earlier discussions BTW :D

Let's keep the configuration name as it's :) As I forgot in new Ecotone version, the custom Symfony configuration will be dropped in favour of ServiceContext configuration.

someniatko commented 1 year ago

I will do a PR soon