8000 New Preloader related issues causing "Failed opening required '/var/www\vendor/autoload.php'" · Issue #38123 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

New Preloader related issues causing "Failed opening required '/var/www\vendor/autoload.php'" #38123

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
ralusnom opened this issue Sep 9, 2020 · 6 comments

Comments

@ralusnom
Copy link
ralusnom commented Sep 9, 2020

Symfony version(s) affected: 5.1.6

Description

Path resolution does not work with the newly integrated cache handler cache/Xxx_KernelProdDebugContainer.preload.php

require dirname(__DIR__, 3).'\\vendor/autoload.php';

The two backslashes are resolved to this square character: .\�endor/autoload.php (see picture) since \v is an escape secquence for vertical jumps, as far as I remember.

The screenshot below show the debug output.

How to reproduce

  • $ composer dump-env prod
  • Open web page
  • 💣

Possible Solution
Also, dirname(__DIR__,3) doesnt resolve correctly (might be a configuration issue from my side/app).
The only temp solution is to change to this weird non-scalable path settings:

require __DIR__.'/../../../vendor/autoload.php'; <-- changed
require __DIR__.'/ContainerU2aLZw8/Vince_KernelProdDebugContainer.php';

Additional context
image

@ralusnom
Copy link
Author
ralusnom commented Sep 9, 2020

I see, the issue starts when the DebugContainer is generated in vendor/symfony/dependency-injection/Dumper/PhpDumper.php:329
image

I also need to add that I'm working on a Windows machine and empty the cache from the local command line. The app itself runs in a docker container with Apache on Ubuntu.

This means that before $autoloadFile = trim($this->export($autoloadFile), '()\\'); the variable $autoloadFile has a Windows path format.

@nicolas-grekas
Copy link
Member

Can you please try this patch?

It changes back-slashes into forward-slashes in dumped containers, making them path-independent.

--- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
+++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
@@ -2056,7 +2056,13 @@ EOF;
             $suffix = $matches[0][1] + \strlen($matches[0][0]);
             $matches[0][1] += \strlen($matches[1][0]);
             $prefix = $matches[0][1] ? $this->doExport(substr($value, 0, $matches[0][1]), true).'.' : '';
-            $suffix = isset($value[$suffix]) ? '.'.$this->doExport(substr($value, $suffix), true) : '';
+
+            if ('\\' === \DIRECTORY_SEPARATOR && isset($value[$suffix])) {
+                $suffix = '.'.$this->doExport(str_replace('\\', '/', substr($value, $suffix)), true);
+            } else {
+                $suffix = isset($value[$suffix]) ? '.'.$this->doExport(substr($value, $suffix), true) : '';
+            }
+
             $dirname = $this->asFiles ? '$this->containerDir' : '__DIR__';
             $offset = 2 + $this->targetDirMaxMatches - \count($matches);

@ralusnom
Copy link
Author
ralusnom commented Sep 9, 2020

Yes, it's getting better, but then it's failing for the twig imports. I changed the first require_once manually.

image

I also had to remove

...
#12 require dirname(__DIR__, 3).'/vendor/autoload.php';
#13 require __DIR__.'/ContainerTTUj7xS/Vince_KernelProdDebugContainer.php';
...

because of
Compile Error: Cannot declare class ContainerTTUj7xS\Vince_KernelProdDebugContainer, because the name is already in use

@fabpot
Copy link
Member
fabpot commented Sep 9, 2020

Problem comes from the fact that the preload.php file is stored under src/, which is managed by the DebugClassLoader. So, we either need to have some special treatment for the file, or move it elsewhere.

@ralusnom
Copy link
Author
ralusnom commented Sep 9, 2020

Pulling it out of src would be advantageous. At least I had to exclude it from the service configuration as well.
This is not a class/file that needs to be managed in src, right? Or is it intended that this file can be adjusted manually later?

@ralusnom
Copy link
Author
ralusnom commented Sep 9, 2020

...ahm... I think this solved the issue. After extending service exlusion by preload.php

  App\:
    resource: '../src/App/*'
    exclude: '../src/App/{[....],Kernel.php,preload.php}'

And it now even works without the suggested changes from Nikolas.

Did you mention this somewhere in the docs?

@fabpot fabpot closed this as completed Sep 10, 2020
fabpot added a commit that referenced this issue Sep 10, 2020
This PR was merged into the 4.4 branch.

Discussion
----------

[FrameworkBundle] adopt src/.preload.php

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #38123
| License       | MIT
| Doc PR        | -

The leading dot prevents PSR-4 discovery from considering the file.

Commits
-------

f4c47eb [FrameworkBundle] adopt src/.preload.php
fabpot added a commit that referenced this issue Sep 10, 2020
…olas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[DI] dump OS-indepent paths in the compiled container

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #38123
| License       | MIT
| Doc PR        | -

This allows compiling on Windows and running on Linux (Docker).

Commits
-------

4dcf9e7 [DI
6B59
] dump OS-indepent paths in the compiled container
fabpot added a commit that referenced this issue Sep 10, 2020
…rekas)

This PR was merged into the 5.1 branch.

Discussion
----------

[DI] dump OS-indepent paths in the preload file

| Q             | A
| ------------- | ---
| Branch?       | 5.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #38123
| License       | MIT
| Doc PR        | -

This allows generating the file on Windows and running it on Linux (Docker).

Commits
-------

e8feba5 [DI] dump OS-indepent paths in the preload file
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

4 participants
0