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

Autowire of repositories not working properly #241

Closed
Gonzalo1987 opened this issue Apr 13, 2022 · 10 comments
Closed

Autowire of repositories not working properly #241

Gonzalo1987 opened this issue Apr 13, 2022 · 10 comments
Labels
bug stalled support Support requested

Comments

@Gonzalo1987
Copy link

Gonzalo1987 commented Apr 13, 2022

Hello,
I'm trying to dockerize a Symfony 5.4 project that is currently working on, after follow the instructions here indicated: https://github.com/dunglas/symfony-docker/blob/main/docs/existing-project.md

and after build my dockerfile, I've get that my php container is rebooting randomly
This is probably caused, for some problem regarding the autowired services.

The folder 'App\Repository' seems not be autowired, that cause the container exit with code 1 trying to make the cache:clear.

php_1       | Script cache:clear returned with error code 1
php_1       | !!
php_1       | !!  In DefinitionErrorExceptionPass.php line 54:
php_1       | !!
php_1       | !!    Cannot autowire service "App\Service\TokenToTransfer\TransferDetailsGenerat
php_1       | !!    or": argument "$tokenToTransferRepository" of method "__construct()" refere
php_1       | !!    nces class "App\Repository\TokenToTransferRepository" but no such service e
php_1       | !!    xists.
php_1       | !!
php_1       | !!
php_1       | !!
php_1       | Script @auto-scripts was called via post-install-cmd
sto4all_dockerized_php_1 exited with code 1

(I've add manually that repository in the services.yaml making that error gone, but after that other services failed because other repositories failing to autowiring)

That folder should be autowired because the service.yaml config:

services: 
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
        
    App\:
        resource: '../src/'
        exclude:
            - '../src/DependencyInjection/'
            - '../src/Entity/'
            - '../src/Kernel.php'
            - '../src/Tests/'

This project and configuration is working nicely with in local machine (w10) and in the prod server (centos) using php 8.0 with apache.

Moreover the other services of the project seems to be autowired perfectly, but I can't make this container work for this problem.

Any advice?

@thePanz
Copy link
Contributor

thePanz commented Apr 23, 2022

@Gonzalo1987 I was facing the same issues, and realized that some sub-folders of src/ were not readable by the php-fpm process.
Can you check that those folders have the right permissions?

@Gonzalo1987
Copy link
Author

Thanks for the support @thePanz ,
I've check the permissions of my container, and /app folder and subfolders (at least /app/src and /app/src/Repository) has 777 permissions for every file.
It would be possible it wasn't readable by php-fpm, but when I put the repositories as independant services (without use the autowire although is enabled and works for the services in /Service folder) it works:

services.yaml

services: 
    App\Repository\XRepository:
    App\Repository\YRepository:
    App\Repository\ZRepository:

@Gonzalo1987
Copy link
Author

Seems related to: #166

@maxhelias
Copy link
Collaborator

Can you try to disable apcu and/or opcache in your develpment like explain here : #245

@maxhelias maxhelias added bug support Support requested labels May 3, 2022
@Gonzalo1987
Copy link
Author

Sorry @maxhelias but still not autowiring the repository services :(

@maxhelias
Copy link
Collaborator

And this solution : #226 (comment)

@maxhelias
Copy link
Collaborator

I think it's related to filesystem/volumes sync between docker and the locale machine

@Gonzalo1987
Copy link
Author

Yes, you are right, if I remove the line: - ./:/srv/app:rw,cached of my docker-compose.override.yaml it works.

Seems something related to the sync. A little annoying, it would be a docker desktop bug?

@maxhelias
Copy link
Collaborator

I don't know if it's docker or the filesystem provided for the OS but I often hear synchronization problems on windows.
Personally I am on macOS and apart from the historical slowdowns which have been corrected on the last versions I never had this kind of problem.

@tsiatka
Copy link

tsiatka commented Feb 2, 2024

Same issue here, any solution ?

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

No branches or pull requests

4 participants