Skip to content
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

entryToMethodMapping differs from methods #638

Open
R4c00n opened this issue Nov 8, 2018 · 3 comments
Open

entryToMethodMapping differs from methods #638

R4c00n opened this issue Nov 8, 2018 · 3 comments
Labels

Comments

@R4c00n
Copy link

R4c00n commented Nov 8, 2018

Hello,
we're using PHP DI with enableCompilation in one of our projects for a month now.
Everything was fine so far, but today we got the following error:

Uncaught Error: Call to undefined method CompiledContainer::get5be411f2b95a9452835510() in /directory/vendor/php-di/php-di/src/CompiledContainer.php:53

After investigating a bit we discovered that the generated CompiledContainer class has non-existing methods defined in the METHOD_MAPPING array.

/**
 * This class has been auto-generated by PHP-DI.
 */
class CompiledContainer extends DI\CompiledContainer{
    const METHOD_MAPPING = array (
  'foo' => 'get5be411f2b95a9452835510',
);

    protected function get5be416fb8c215047641051()
    {
        return new foo();
    }
}

I took a look at the part which generates the CompiledContainer file and can't see a reason how this can happen.
Do you have any ideas or has anyone experienced this behavior before?

Our deployment process cleans the cache directory and runs a PHP script that builds a container instance to generate the cache file.

@mnapoli mnapoli added the bug label Nov 16, 2018
@mnapoli
Copy link
Member

mnapoli commented Nov 16, 2018

Thanks for the report. Here is a possible scenario:

  • we add to the $entryToMethodMapping variable:

$this->entryToMethodMapping[$entryName] = $methodName;

  • but sometimes we also unset from there:

// forget the entry
unset($this->entryToMethodMapping[$entryName]);

  • however we also add the methods to generate to $methods:

$this->methods[$methodName] = $code;

But we never unset() here too!

So I don't know why/when/how but maybe we generate the method a first time, then it is unset() in the first variable (not the second one). That could be a lead to follow. FYI that unset() was introduced here: #569

Also could you please detail what kind of definition it is?

@pbabilas
Copy link

pbabilas commented Feb 13, 2019

I come across the exact same problem:

{"message":"Uncaught Exception Error: "Call to undefined method CompiledContainer::get5c62ebc964075786890556()" at /var/www/vendor/php-di/php-di/src/CompiledContainer.php line 53","context":{"exception":{"class":"Error","message":"Call to undefined method CompiledContainer::get5c62ebc964075786890556()","code":0,"file":"/var/www/vendor/php-di/php-di/src/CompiledContainer.php:53"}}

It used to happen when my demo or stage environment are starting. We compile container during the build, and it is in Docker image, but id does not have this method or mapping with that id. Dunno what to do next. In 30% of cases we have this problem. Any idea how to work with this, or debug?

And I'm afraid I can't get the definition over this problem cause I've get report from CI and my env is not running anymore at this moment. I will try to set some logger to it.

@pbabilas
Copy link

pbabilas commented Feb 18, 2019

OK, i've found problem but dunno how does it appears... My deployment process looks like that:
We apply deployment with 2 containers.
first is volume with code, and second is php + nginx. When volume and php is ready volume starts copying files into shared volume. All readiness are set. So no requests are send before all process is done. Volume has precompiled Container in docker image but php di compile it's own container and adds it to ram via opcache. Compiled build file is ok in tmp dir, but completly different and broken file is in ram. How it is possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants