Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DebugClassLoader] Can't recover on a failed required file #32499

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

Closed
fancyweb opened this issue Jul 11, 2019 · 10 comments
Closed

[DebugClassLoader] Can't recover on a failed required file #32499

fancyweb opened this issue Jul 11, 2019 · 10 comments

Comments

@fancyweb
Copy link
Contributor

Symfony version(s) affected: all

Description
In the DebugClassLoader, classes that are found by the wrapped class loader findFile() method are required (and not included like in the composer ClassLoader for example). That means that if the file is not found, the fatal error that is triggered is not recoverable.

So why would the wrapped class loader finds the file but the file doesn't actually exist? With Composer, it can happen if you dump your autoload files with the optimize option and if you delete a class file for example. The class will still be in the Composer class map.

What problem does it cause? When you do reflection on a class like this, it ends up with a fatal error instead of a \ReflectionException. In Symfony, that breaks the AnnotationCacheWarmer process that is supposed to ignore \ReflectionExceptions on classes that don't exist.

Possible Solution

  • Check if the file exists before requiring it in the DebugClassLoader : I guess it would be very bad for performance.
  • Create a SafeDebugClassLoader that wraps the DebugClassLoader to check if the file exists, so we can enable it / disable it on demand?

@nicolas-grekas 🙏

@nicolas-grekas
Copy link
Member

Duplicate of #32395?

@fancyweb
Copy link
Contributor Author

fancyweb commented Jul 11, 2019

Including the missing file would generate a warning that we could handle to throw a proper exception. But including instead of requiring would be a breaking change I guess.

Somehow related : throwing an exception in a class loader behaves differently since PHP 7.3 (cf https://3v4l.org/OQPk9). I think that the throwOnRequiredClass method that is used in Symfony code is impacted and might now work correctly if a previous class loader threw an exception.

@fancyweb
Copy link
Contributor Author

fancyweb commented Jul 11, 2019

Duplicate of #32395?

#32395 looks related to my 2nd point about throwOnRequiredClass but not on the main one.

@nicolas-grekas
Copy link
Member

How does composer deal with the missing file case? I'm not sure we care actually: if you dump the classmap, you must resync it when needed.

@fancyweb
Copy link
Contributor Author

Composer includes the file. So it just produces a warning + the class is not found + a \ReflectionException is thrown at the end of all class loaders calls since the class was never found.

@nicolas-grekas
Copy link
Member

Let's do the same? Use include instead of require?

@fancyweb
Copy link
Contributor Author

That's the easiest way but that's a big change for userland isn't it? We might break some workflows.

However, doing it would resolve my bug in the AnnotationCacheWarmer since a \ReflectionException would be thrown by PhpArrayAdapter::throwOnRequiredClass() method and then get caught by the current catch block.

@nicolas-grekas
Copy link
Member

What would break?

@fancyweb
Copy link
Contributor Author

fancyweb commented Jul 11, 2019 via email

@nicolas-grekas
Copy link
Member

Please do, thanks.

@fabpot fabpot closed this as completed Jul 12, 2019
fabpot added a commit that referenced this issue Jul 12, 2019
…equiring them (fancyweb)

This PR was merged into the 3.4 branch.

Discussion
----------

[Debug][DebugClassLoader] Include found files instead of requiring them

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

It fixes #32499 + it makes the `DebugClassLoader` behaves like composer `ClassLoader` that is very likely the wrapped class loader.

Commits
-------

c7141c8 [Debug][DebugClassLoader] Include found files instead of requiring them
nicolas-grekas added a commit that referenced this issue 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
symfony-splitter pushed a commit to symfony/config that referenced this issue 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 | symfony/symfony#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
-------

dbd9b75d86 [FrameworkBundle][Config] Ignore exeptions thrown during reflection classes autoload
symfony-splitter pushed a commit to symfony/framework-bundle that referenced this issue 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 | symfony/symfony#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
-------

dbd9b75d86 [FrameworkBundle][Config] Ignore exeptions thrown during reflection classes autoload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants