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

[FrameworkBundle][Config] Ignore exceptions thrown during reflection classes autoload #32516

Conversation

fancyweb
Copy link
Contributor

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #32499 with PHP 7.3+
License MIT
Doc PR -

The behavior when an exception is thrown in a class loader changed in PHP 7.3 (cf https://3v4l.org/OQPk9). That means that the throwOnRequiredClass trick that is done in the parent class of these cache warmers (AbstractPhpFileCacheWarmer) does not work anymore with PHP7.3+.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jul 12, 2019

I'm not sure we need to work around since the new behavior has been reverted on <7.4
See #32395
For 7.4, there are more places that need to be changed, and I'd like we really understand the best way to fix the root issue.

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Jul 12, 2019
@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jul 12, 2019

Hmm, this is different and discussed in https://bugs.php.net/74372
@nikic can we consider fixing the BC break by having the new behavior only for child classes of Error and let Exception behave as before?

@nikic
Copy link
Contributor

nikic commented Jul 12, 2019

@nicolas-grekas I don't think introducing an Error/Exception distinction here makes sense. If you want to ignore exceptions, please ignore them explicitly.

We could revert from 7.3 and introduce in a later version, but given that we're at 7.3.8 already and this change is explicitly called out in the migration guide, I'm not sure doing that is a good idea. You'll have to deal with it at some point in either case...

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jul 12, 2019

@nikic thanks for the feedback, OK.

@fancyweb I think the patch should be only this one:

--- a/src/Symfony/Component/Config/Resource/ClassExistenceResource.php
+++ b/src/Symfony/Component/Config/Resource/ClassExistenceResource.php
@@ -76,11 +76,12 @@ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializ
 
             try {
                 $exists = class_exists($this->resource) || interface_exists($this->resource, false) || trait_exists($this->resource, false);
-            } catch (\ReflectionException $e) {
+            } catch (\Throwable $e) {
                 if (0 >= $timestamp) {
                     unset(self::$existsCache[1][$this->resource]);
                     throw $e;
                 }
+                $exists = class_exists($this->resource, false) || interface_exists($this->resource, false) || trait_exists($this->resource, false);
             } finally {
                 self::$autoloadedClass = $autoloadedClass;
                 if (!--self::$autoloadLevel) {

The other places should not be changed (according to my current understanding at least.)

@nicolas-grekas
Copy link
Member

OK, I missed the } catch (\ReflectionException $e) { in warmers, I understand how the issue propagates here. We should factorize this logic now, inside throwOnRequiredClass I believe.

@fancyweb fancyweb force-pushed the cache-warmer-ignore-reflection-exception-during-class-autoload branch from 2f420b6 to 0816b13 Compare July 12, 2019 15:39
@fancyweb
Copy link
Contributor Author

fancyweb commented Jul 12, 2019

@nicolas-grekas Just pushed all tests + a deduplication of the code. I don't think it was what you wanted so I'm waiting for your feedback 😁

@nicolas-grekas
Copy link
Member

ClassExistenceResource::isFresh() is also affected + any direct user of PhpArrayAdapter::throwOnRequiredClass() would too.
The plan could be:

  • factorize in ClassExistenceResource
  • find a way to use ClassExistenceResource instead of PhpArrayAdapter in FrameworkBundle
  • don't patch PhpArrayAdapter but deprecate its throwOnRequiredClass() in 4.4

@fancyweb fancyweb force-pushed the cache-warmer-ignore-reflection-exception-during-class-autoload branch 3 times, most recently from 63bbf4c to 2f39c7e Compare July 16, 2019 10:31
@fancyweb
Copy link
Contributor Author

fancyweb commented Jul 16, 2019

@nicolas-grekas

factorize in ClassExistenceResource

Done.

find a way to use ClassExistenceResource instead of PhpArrayAdapter in FrameworkBundle

symfony/config is a requirement of the FrameworkBundle so it's alright.

don't patch PhpArrayAdapter but deprecate its throwOnRequiredClass() in 4.4

Actually this method was introduced directly as @internal, so I just removed it.

$reader->getMethodAnnotations($reflectionMethod);
try {
$reader->getMethodAnnotations($reflectionMethod);
} catch (AnnotationException $e) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another fix / improvement. Moving this catch on every calls allows to not fail totally on first fail but just on each failing cases.

@fancyweb fancyweb changed the title [FrameworkBundle][CacheWarmer] Ignore exeptions thrown during reflection classes autoload [FrameworkBundle][CacheWarmer] Ignore exceptions thrown during reflection classes autoload Jul 16, 2019
@fancyweb fancyweb force-pushed the cache-warmer-ignore-reflection-exception-during-class-autoload branch 5 times, most recently from f609060 to 1782e42 Compare July 17, 2019 07:11
@fancyweb fancyweb force-pushed the cache-warmer-ignore-reflection-exception-during-class-autoload branch 3 times, most recently from 9f23898 to 5df2ceb Compare July 22, 2019 22:18
@fancyweb fancyweb force-pushed the cache-warmer-ignore-reflection-exception-during-class-autoload branch 3 times, most recently from ef3229e to d13f943 Compare July 26, 2019 15:42
@fancyweb fancyweb force-pushed the cache-warmer-ignore-reflection-exception-during-class-autoload branch 2 times, most recently from fd5bc1e to ccf2004 Compare August 6, 2019 10:13
@nicolas-grekas nicolas-grekas force-pushed the cache-warmer-ignore-reflection-exception-during-class-autoload branch from ccf2004 to bf467cc Compare August 6, 2019 15:39
@nicolas-grekas nicolas-grekas changed the title [FrameworkBundle][CacheWarmer] Ignore exceptions thrown during reflection classes autoload [FrameworkBundle][Config] Ignore exceptions thrown during reflection classes autoload Aug 6, 2019
@nicolas-grekas nicolas-grekas force-pushed the cache-warmer-ignore-reflection-exception-during-class-autoload branch from bf467cc to 1f06925 Compare August 6, 2019 15:41
@nicolas-grekas nicolas-grekas force-pushed the cache-warmer-ignore-reflection-exception-during-class-autoload branch from 1f06925 to dbd9b75 Compare August 6, 2019 16:40
@nicolas-grekas
Copy link
Member

Thank you @fancyweb.

@nicolas-grekas nicolas-grekas merged commit dbd9b75 into symfony:3.4 Aug 7, 2019
nicolas-grekas added a commit that referenced this pull request Aug 7, 2019
…reflection classes autoload (fancyweb)

This PR was merged into the 3.4 branch.

Discussion
----------

[FrameworkBundle][Config] Ignore exceptions thrown during reflection classes autoload

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #32499 with PHP 7.3+
| License       | MIT
| Doc PR        | -

The behavior when an exception is thrown in a class loader changed in PHP 7.3 (cf https://3v4l.org/OQPk9). That means that the `throwOnRequiredClass` trick that is done in the parent class of these cache warmers (`AbstractPhpFileCacheWarmer`) does not work anymore with PHP7.3+.

Commits
-------

dbd9b75 [FrameworkBundle][Config] Ignore exeptions thrown during reflection classes autoload
@fancyweb fancyweb deleted the cache-warmer-ignore-reflection-exception-during-class-autoload branch August 7, 2019 14:38
This was referenced Aug 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants