kimai2 icon indicating copy to clipboard operation
kimai2 copied to clipboard

[BUG] Error reloading cache: Cannot autowire service

Open varunpan opened this issue 2 years ago • 13 comments

Describe the bug I pulled new image and now getting an error when reloading cache. I attempted to manually rebuild the cache and getting the same error when running the cache:clear and cache:warmup or any another bin/console functions.

To Reproduce

  1. docker pull kimai
  2. reloaded cache: docker exec -ti kimai /opt/kimai/bin/console kimai:reload --env=prod
  3. See error:
In DefinitionErrorExceptionPass.php line 54:
                                                                                                               
  Cannot autowire service "App\Utils\MPdfConverter": argument "$cacheDirectory" of method "__construct()" is   
  type-hinted "string", you should configure its value explicitly.

Additional context

  • Kimai version: Not sure, unable to run any bin/console functions
  • PHP version: 8.1.9
  • Device: Linux 5.18.0-0.deb11.3-amd64 Debian
  • Browser Firefox 104

varunpan avatar Sep 05 '22 15:09 varunpan

I don't understand this. kimai isn't the correct image name.

Can you show the output of this command please?

docker ps -a | grep kimai

tobybatch avatar Sep 05 '22 15:09 tobybatch

Im sorry it was docker pull kimai2:fpm

varunpan avatar Sep 05 '22 15:09 varunpan

Is this started as a docker-compose tear up? what is running the web proxy for the FPM instance?

And I guess it's actually

docker pull kimai/kimai2:fpm

tobybatch avatar Sep 05 '22 15:09 tobybatch

Can you post the output of

docker ps -a

tobybatch avatar Sep 05 '22 15:09 tobybatch

@tobybatch It is correct that the service definition was changed for this release, see line: https://github.com/kevinpapst/kimai2/blob/master/config/services.yaml#L59

But it is not correct that this error is thrown. Can't tell you if this is some kind of weird cache problem or an update problem though. The only idea I have is to remove the existing cache with a hard rm -rf /opt/kimai/var/cache/prod/*, followed by the "soft reload" command.

kevinpapst avatar Sep 05 '22 15:09 kevinpapst

sure it is:

CONTAINER ID   IMAGE                               COMMAND                  CREATED        STATUS                  PORTS                                   NAMES
74e091e1fb43   tobybatch/nginx-fpm-reverse-proxy   "nginx -g 'daemon of…"   10 hours ago   Up 10 hours             0.0.0.0:8008->80/tcp, :::8008->80/tcp   kimai_server
f1415ba830e5   kimai/kimai2:fpm                    "/bin/sh -c /startup…"   10 hours ago   Up 10 hours (healthy)   9000/tcp                                kimai
683f59f62bae   mysql:5.7                           "docker-entrypoint.s…"   10 hours ago   Up 10 hours (healthy)   3306/tcp, 33060/tcp                     kimai_db
3f164583988b   catatnight/postfix:latest           "/bin/sh -c '/opt/in…"   10 hours ago   Up 10 hours                                                     kimai_postfix

varunpan avatar Sep 06 '22 00:09 varunpan

The only idea I have is to remove the existing cache with a hard rm -rf /opt/kimai/var/cache/prod/*, followed by the "soft reload" command.

I did remove manually remove the cache and tried to manually rebuild the cache, but getting the same error when trying to run any type of bin/console command.

varunpan avatar Sep 06 '22 00:09 varunpan

Is this started as a docker-compose tear up? what is running the web proxy for the FPM instance?

Yes, see below my docker compose file:

version: '3.5'
networks:
  panchnet:
    external: true
services:
  sqldb:
    image: mysql:5.7
    container_name: kimai_db
    environment:
      - MYSQL_DATABASE=${MYSQL_DATABASE}
      - MYSQL_USER=${MYSQL_USER}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - PUID=1000
      - PGID=1000
      - TZ=America/New_York
    volumes:
      - /home/docker/kimai/mysql:/var/lib/mysql
    command: --default-storage-engine innodb
    restart: unless-stopped
    healthcheck:
      test: mysqladmin -p$$MYSQL_ROOT_PASSWORD ping -h localhost
      interval: 20s
      start_period: 10s
      timeout: 10s
      retries: 3
    networks:
      panchnet:
        ipv4_address: 172.18.5.247

  server:
    image: tobybatch/nginx-fpm-reverse-proxy
    container_name: kimai_server
    ports:
      - 8008:80
    volumes:
      - /home/docker/kimai/public:/opt/kimai/public:ro
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/New_York
    restart: unless-stopped
    depends_on:
      - kimai
#    healthcheck:
#      test:  wget --spider http://nginx/health || exit 1
#      interval: 20s
#      start_period: 10s
#      timeout: 10s
#      retries: 3
    networks:
      panchnet:
        ipv4_address: 172.18.5.246

  kimai: # This is the latest FPM image of kimai
    image: kimai/kimai2:fpm
    container_name: kimai
    environment:
      - ADMINMAIL=${ADMINMAIL}
      - ADMINPASS=${ADMINPASS}
      - DATABASE_URL=mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@sqldb/${MYSQL_DATABASE}
      - TRUSTED_HOSTS=server,192.168.1.4,172.18.5.199,kimai.panchnet.duckdns.org
      - PUID=1000
      - PGID=1000
      - TZ=America/New_York
    volumes:
      - /home/docker/kimai/public:/opt/kimai/public
      - /home/docker/kimai/var:/opt/kimai/var
      - /home/docker/kimai/config:/opt/kimai/config
      # - ./ldap.conf:/etc/openldap/ldap.conf:z
      # - ./ROOT-CA.pem:/etc/ssl/certs/ROOT-CA.pem:z
    depends_on:
      - sqldb
    restart: unless-stopped
    networks:
      panchnet:
        ipv4_address: 172.18.5.245

  postfix:
    image: catatnight/postfix:latest
    container_name: kimai_postfix
    environment:
      maildomain: panchnet.duckdns.org
      smtp_user: ${MYSQL_USER}:${MYSQL_PASSWORD}
      PUID: 1000
      PGID: 1000
      TZ: America/New_York
    restart: unless-stopped
    networks:
      panchnet:
        ipv4_address: 172.18.5.244

varunpan avatar Sep 06 '22 00:09 varunpan

@kevinpapst I can't reproduce this error but I am getting this when I run composer install in the running instance. The weird thing is if this command failed during the container creation we would be getting an error in the github build action.

bash-5.1$ composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Package symfony/debug is abandoned, you should avoid using it. Use symfony/error-handler instead.
Package symfony/inflector is abandoned, you should avoid using it. Use EnglishInflector from the String component instead.
Generating autoload files
composer/package-versions-deprecated: Generating version class...
composer/package-versions-deprecated: ...done generating version class
140 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

Run composer recipes at any time to see the status of your Symfony recipes.

Executing script cache:clear [KO]
 [KO]
Script cache:clear returned with error code 255
!!  Symfony\Component\ErrorHandler\Error\ClassNotFoundError {#86
!!    #message: """
!!      Attempted to load class "TablerBundle" from namespace "KevinPapst\TablerBundle".\n
!!      Did you forget a "use" statement for another namespace?
!!      """
!!    #code: 0
!!    #file: "./src/Kernel.php"
!!    #line: 106
!!    trace: {
!!      ./src/Kernel.php:106 {
!!        App\Kernel->registerBundles()
!!        › if (isset($envs['all']) || isset($envs[$this->environment])) {
!!        ›     yield new $class();
!!        › }
!!      }
!!      ./vendor/symfony/http-kernel/Kernel.php:446 { …}
!!      ./vendor/symfony/http-kernel/Kernel.php:133 { …}
!!      ./vendor/symfony/framework-bundle/Console/Application.php:169 { …}
!!      ./vendor/symfony/framework-bundle/Console/Application.php:75 { …}
!!      ./vendor/symfony/console/Application.php:149 { …}
!!      ./bin/console:29 { …}
!!    }
!!  }
!!  2022-09-06T08:25:50+00:00 [critical] Uncaught Error: Class "KevinPapst\TablerBundle\TablerBundle" not found
!!  
Script @auto-scripts was called via post-install-cmd

But I can't see that bundle anywhere.

bash-5.1$ find . -name "TablerBundle"
bash-5.1$ grep TablerBundle *
bash-5.1$ grep TablerBundle composer.json 
bash-5.1$ grep -i tabler composer.json 

and finally

bash-5.1$ grep -r TablerBundle .
./config/packages/tabler.yaml:# https://github.com/kevinpapst/TablerBundle/blob/master/Resources/docs/configurations.md
./config/packages/twig.yaml:        '%kernel.project_dir%/templates/bundles/TablerBundle': theme
./config/bundles.php:    KevinPapst\TablerBundle\TablerBundle::class => ['all' => true],
./var/installed:Symfony\Component\ErrorHandler\Error\ClassNotFoundError {#86 #message: """ Attempted to load class "TablerBundle" from namespace "KevinPapst\TablerBundle".\n Did you forget a "use" statement for another namespace? """ #code: 0 #file: "/opt/kimai/src/Kernel.php" #line: 106 trace: { /opt/kimai/src/Kernel.php:106 { App\Kernel->registerBundles() › if (isset($envs['all']) || isset($envs[$this->environment])) { › yield new $class(); › } } /opt/kimai/vendor/symfony/http-kernel/Kernel.php:446 { …} /opt/kimai/vendor/symfony/http-kernel/Kernel.php:133 { …} /opt/kimai/vendor/symfony/framework-bundle/Console/Application.php:169 { …} /opt/kimai/vendor/symfony/framework-bundle/Console/Application.php:75 { …} /opt/kimai/vendor/symfony/console/Application.php:149 { …} /opt/kimai/bin/console:29 { …} } }

tobybatch avatar Sep 06 '22 08:09 tobybatch

@tobybatch you are posting an output from the next major version. The package "TablerBundle" is not in 1.24 but only in 2.0

kevinpapst avatar Sep 06 '22 09:09 kevinpapst

I reverted back to kimai/kimai2:fpm-1.23.1-prod image and it works, so it seems to be related to this update to 1.24 in the latest.

varunpan avatar Sep 06 '22 18:09 varunpan

@kevinpapst It shouldn't but looks like it may an issue with the github action.

Thanks, I'll take a look

tobybatch avatar Sep 07 '22 09:09 tobybatch

Still getting the error when using the latest tag:

docker exec -ti kimai /opt/kimai/bin/console kimai:reload --env=prod

                                                                                                                        
 [WARNING] Some commands could not be registered:                                                                       
                                                                                                                        

In MPdfConverter.php line 30:
                                                                                                                              
  App\Utils\MPdfConverter::__construct(): Argument #1 ($fileHelper) must be of type App\Utils\FileHelper, string given, call  
  ed in /opt/kimai/var/cache/prod/ContainerKsCkY9m/getServiceInvoiceService.php on line 54                                    
                                                                                                                              


                                                                                                                        
 [WARNING] Some commands could not be registered:                                                                       
                                                                                                                        

In MPdfConverter.php line 30:
                                                                                                                              
  App\Utils\MPdfConverter::__construct(): Argument #1 ($fileHelper) must be of type App\Utils\FileHelper, string given, call  
  ed in /opt/kimai/var/cache/prod/ContainerKsCkY9m/getServiceInvoiceService.php on line 54                                    
                                                                                                                              


Reloading configurations ...
============================


                                                                                                                        
 [OK] All 40 YAML files contain valid syntax.                                                                           
                                                                                                                        



                                                                                                                        
 [OK] All 514 XLIFF files contain valid syntax.                                                                         
                                                                                                                        


 Rebuilding your cache, please be patient ...

 // Clearing the cache for the prod environment with debug false                                                        


                                                                                                                        
 [ERROR] Cannot autowire service "App\Utils\MPdfConverter": argument "$cacheDirectory" of method "__construct()" is     
         type-hinted "string", you should configure its value explicitly.                                               
                                                                                                                        

                                                                                                                        
 [WARNING] Cache could not be rebuilt.                                                                                  
                                                                                                                        
           Please run these commands to rebuild the cache manually:                                                     
                                                                                                                        
           rm -r var/cache/*                                                                                            
           bin/console cache:clear --env=prod                                                                           
           bin/console cache:warmup --env=prod                                                                          
                                                                                                                        


Kimai version: 1.25.0

varunpan avatar Sep 26 '22 14:09 varunpan

@varunpan Is this still an issue?

tobybatch avatar Oct 28 '22 08:10 tobybatch

@tobybatch Yes I just tried the latest version 1.30 and still getting the issue, I'm not sure. I might just backup my DB and start over on a new server.

varunpan avatar Apr 08 '23 13:04 varunpan

@tobybatch I figured it out! It was user error as always. I am now on the latest 1.30 version. Thank you for help on this!

varunpan avatar Apr 16 '23 12:04 varunpan