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

Don't fail if the cached type is not ClassMetadata #717

Closed
wants to merge 1 commit into from

Conversation

Maks3w
Copy link
Contributor

@Maks3w Maks3w commented May 10, 2016

This is a random error and I didn't found yet how to reproduce it. It may related with Zend OPCache as usuallly is thrown while hot deploy new versions

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Doctrine\\ORM\\Mapping\\ClassMetadataFactory::wakeupReflection() must implement interface Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata, array given,
called in /v2/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php on line 214 and defined in /v2/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:718
Stack trace:
#0 /v2/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php(214): Doctrine\\ORM\\Mapping\\ClassMetadataFactory->wakeupReflection(Array, Object(Doctrine\\Common\\Persistence\\Mapping\\RuntimeReflectionService))
#1 /v2/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(281): Doctrine\\Common\\Persistence\\Mapping\\AbstractClassMetadataFactory->getMetadataFor('Model\\\\...')
#2 /v2/vendor/doctrine/orm/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php(44): Doctrine\\ORM\\EntityManager->getClassMetadata('Model\\\\...')
#3 /v2/vendor/doctrine/orm/ in /v2/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 718

This is a random error and I didn't found yet how to reproduce it. It may related with Zend OPCache as usuallly is thrown while hot deploy new versions

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Doctrine\\ORM\\Mapping\\ClassMetadataFactory::wakeupReflection() must implement interface Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata, array given,
called in /v2/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php on line 214 and defined in /v2/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:718
Stack trace:
#0 /v2/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php(214): Doctrine\\ORM\\Mapping\\ClassMetadataFactory->wakeupReflection(Array, Object(Doctrine\\Common\\Persistence\\Mapping\\RuntimeReflectionService))
doctrine#1 /v2/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(281): Doctrine\\Common\\Persistence\\Mapping\\AbstractClassMetadataFactory->getMetadataFor('Model\\\\...')
doctrine#2 /v2/vendor/doctrine/orm/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php(44): Doctrine\\ORM\\EntityManager->getClassMetadata('Model\\\\...')
doctrine#3 /v2/vendor/doctrine/orm/ in /v2/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 718
@Ocramius Ocramius added the Bug label May 10, 2016
@Ocramius Ocramius added this to the 2.6.2 milestone May 10, 2016
@stof
Copy link
Member

stof commented May 10, 2016

Well, the question is why you have an array here ? your cache is corrupted

@Ocramius
Copy link
Member

Regardless of that, the cache layer provides no guarantees, so we are doing something wrong on our side too.

@stof
Copy link
Member

stof commented May 10, 2016

@Ocramius but then, if you want to account for corrupted cache, you would also need to validate that the metadata retrieved from the cache are for the right class, and so on.

@Ocramius
Copy link
Member

Good point. Yes, fixing that is non-trivial
On May 10, 2016 19:01, "Christophe Coevoet" notifications@github.com
wrote:

@Ocramius https://github.com/Ocramius but then, if you want to account
for corrupted cache, you would also need to validate that the metadata
retrieved from the cache are for the right class, and so on.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#717 (comment)

@Maks3w
Copy link
Contributor Author

Maks3w commented May 10, 2016

Just one thing:

Cache issues shouldn't be a reason because the application returns a HTTP 500 error (like a TypeError do). When Memcache server is not available the application does not blow up, just work like if cache is not available.

Two scenarios where I saw this error (environment: VM with Ubuntu 16.04 -fresh installation- Memcache installed)

  1. With OPCache extension installed but not enabled (default settings) 60-80% of requests fail randomly.
  2. With OPCache extension enabled and tuned while deploying (files hot replacing with release symbolic links) until OPCache is cleared

@Maks3w
Copy link
Contributor Author

Maks3w commented Jun 7, 2016

I was able to capture the values involved in the error

var_dump($realClassName);
string(19) "AcmeCore\Model\User"

var_dump($this->cacheSalt);
string(14) "$CLASSMETADATA"

var_dump($cached);
array(7) {
["Doctrine\ORM\Mapping\Entity"]=>
object(Doctrine\ORM\Mapping\Entity)#308 (2) {
["repositoryClass"]=>
string(14) "UserRepository"
["readOnly"]=>
bool(false)
}
["Doctrine\ORM\Mapping\EntityListeners"]=>
object(Doctrine\ORM\Mapping\EntityListeners)#309 (1) {
["value"]=>
array(1) {
[0]=>
string(12) "UserListener"
}
}
["Doctrine\ORM\Mapping\InheritanceType"]=>
object(Doctrine\ORM\Mapping\InheritanceType)#310 (1) {
["value"]=>
string(12) "SINGLE_TABLE"
}
["Doctrine\ORM\Mapping\DiscriminatorColumn"]=>
object(Doctrine\ORM\Mapping\DiscriminatorColumn)#311 (5) {
["name"]=>
string(4) "type"
["type"]=>
string(6) "string"
["length"]=>
NULL
["fieldName"]=>
NULL
["columnDefinition"]=>
NULL
}
["Doctrine\ORM\Mapping\DiscriminatorMap"]=>
object(Doctrine\ORM\Mapping\DiscriminatorMap)#312 (1) {
["value"]=>
array(2) {
["user"]=>
string(4) "User"
["enterprise"]=>
string(10) "Enterprise"
}
}
["Doctrine\ORM\Mapping\Table"]=>
object(Doctrine\ORM\Mapping\Table)#313 (5) {
["name"]=>
string(4) "User"
["schema"]=>
NULL
["indexes"]=>
array(1) {
[0]=>
object(Doctrine\ORM\Mapping\Index)#314 (4) {
["name"]=>
string(11) "User_status"
["columns"]=>
array(1) {
[0]=>
string(6) "status"
}
["flags"]=>
NULL
["options"]=>
NULL
}
}
["uniqueConstraints"]=>
array(1) {
[0]=>
object(Doctrine\ORM\Mapping\UniqueConstraint)#315 (3) {
["name"]=>
string(10) "User_email"
["columns"]=>
array(1) {
[0]=>
string(5) "email"
}
["options"]=>
NULL
}
}
["options"]=>
array(0) {
}
}
["Doctrine\ORM\Mapping\HasLifecycleCallbacks"]=>
object(Doctrine\ORM\Mapping\HasLifecycleCallbacks)#316 (0) {
}
}

This is the metadata associated to User entity

/**
 * @ORM\Entity(repositoryClass="UserRepository")
 * @ORM\EntityListeners({"UserListener"})
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="type", type="string")
 * @ORM\DiscriminatorMap({"user" = "User", "enterprise" = "Enterprise"})
 * @ORM\Table(
 *  name="User",
 *  uniqueConstraints={@ORM\UniqueConstraint(name="User_email", columns={"email"})},
 *  indexes={@ORM\index(name="User_status", columns={"status"})}
 * )
 * @ORM\HasLifecycleCallbacks()
 */

This one is the Enterprise entity

/**
 * @ORM\Entity(repositoryClass="UserRepository")
 */

@Maks3w
Copy link
Contributor Author

Maks3w commented Jun 7, 2016

Environment

Ubuntu 16.04

$ dpkg -l | grep php
ii  dh-php                              0.10                                all          debhelper add-on to handle PHP PECL extensions
ii  libapache2-mod-php7.0               7.0.4-7ubuntu2.1                    amd64        server-side, HTML-embedded scripting language (Apache 2 module)
ii  newrelic-php5                       6.3.0.161                           amd64        The New Relic agent for PHP
ii  newrelic-php5-common                6.3.0.161                           all          Scripts and samples for the New Relic PHP agent
ii  php-cli                             1:7.0+35ubuntu6                     all          command-line interpreter for the PHP scripting language (default)
ii  php-common                          1:35ubuntu6                         all          Common files for PHP packages
ii  php-memcache                        3.0.9~20151130.fdbd46b-2            amd64        memcache extension module for PHP5
ii  php-pear                            1:1.10.1+submodules+notgz-6         all          PEAR Base System
ii  php-xml                             1:7.0+35ubuntu6                     all          DOM, SimpleXML, WDDX, XML, and XSL module for PHP [default]
ii  php7.0                              7.0.4-7ubuntu2.1                    all          server-side, HTML-embedded scripting language (metapackage)
ii  php7.0-cgi                          7.0.4-7ubuntu2.1                    amd64        server-side, HTML-embedded scripting language (CGI binary)
ii  php7.0-cli                          7.0.4-7ubuntu2.1                    amd64        command-line interpreter for the PHP scripting language
ii  php7.0-common                       7.0.4-7ubuntu2.1                    amd64        documentation, examples and common module for PHP
ii  php7.0-curl                         7.0.4-7ubuntu2.1                    amd64        CURL module for PHP
ii  php7.0-dev                          7.0.4-7ubuntu2.1                    amd64        Files for PHP7.0 module development
ii  php7.0-intl                         7.0.4-7ubuntu2.1                    amd64        Internationalisation module for PHP
ii  php7.0-json                         7.0.4-7ubuntu2.1                    amd64        JSON module for PHP
ii  php7.0-mbstring                     7.0.4-7ubuntu2.1                    amd64        MBSTRING module for PHP
ii  php7.0-mcrypt                       7.0.4-7ubuntu2.1                    amd64        libmcrypt module for PHP
ii  php7.0-mysql                        7.0.4-7ubuntu2.1                    amd64        MySQL module for PHP
ii  php7.0-opcache                      7.0.4-7ubuntu2.1                    amd64        Zend OpCache module for PHP
ii  php7.0-readline                     7.0.4-7ubuntu2.1                    amd64        readline module for PHP
ii  php7.0-soap                         7.0.4-7ubuntu2.1                    amd64        SOAP module for PHP
ii  php7.0-xml                          7.0.4-7ubuntu2.1                    amd64        DOM, SimpleXML, WDDX, XML, and XSL module for PHP
ii  php7.0-zip                          7.0.4-7ubuntu2.1                    amd64        Zip module for PHP
ii  pkg-php-tools                       1.32ubuntu2                         all          various packaging tools and scripts for PHP packages



dpkg -l | grep memcache
ii  libmemcache-dev                     1.4.0.rc2-1.1                       amd64        development headers for libmemcache C client API
ii  libmemcache0                        1.4.0.rc2-1.1                       amd64        C client API for memcached memory object caching system
ii  memcached                           1.4.25-2ubuntu1                     amd64        high-performance memory object caching system
ii  php-memcache                        3.0.9~20151130.fdbd46b-2            amd64        memcache extension module for PHP5

@Ocramius Ocramius self-assigned this Nov 30, 2016
Ocramius added a commit that referenced this pull request Nov 30, 2016
Ocramius added a commit that referenced this pull request Nov 30, 2016
Ocramius added a commit that referenced this pull request Nov 30, 2016
@Ocramius Ocramius closed this in 223a292 Nov 30, 2016
@Ocramius
Copy link
Member

Added tests, merged, backported. Thanks @Maks3w!

master: 223a292
2.6: 26105d3

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

Successfully merging this pull request may close these issues.

None yet

3 participants