tobybatch / kimai2

Docker containers for the kimai2 web application including docker-compose and kubernetes/helm deployment.
MIT License
183 stars 96 forks source link

[BUG] Kimai memory limit read as 500 bytes instead of MB #519

Closed DamianHurschler closed 1 year ago

DamianHurschler commented 1 year ago

Describe the bug The published docker-compose.yml includes the environment variable 'memory_limit=500' for the Kimai container. This is interpreted as 500 bytes and causes errors as this limit would be below the current value, so it can't bet set. This came in with commit 7212829 on Feb 10 and is somewhat related to issue #503. Changing the 'memory_limit' from '500' to '500M' should be read as 500 MB and set an appropriate memory limit. In my case all the errors have gone away and the logs are clean.

To Reproduce Steps to reproduce the behaviour:

  1. Start the container using docker-compose.yml
  kimai: # This is the latest FPM image of kimai
    image: kimai/kimai2:fpm-dev
    environment:
      - ADMINMAIL=admin@kimai.local
      - ADMINPASS=changemeplease
      - DATABASE_URL=mysql://kimaiuser:kimaipassword@sqldb/kimai
      - TRUSTED_HOSTS=nginx,localhost,127.0.0.1
      - memory_limit=500                                                                                         <==
      - MAILER_URL=smtp://mailer:1025
      - MAILER_FROM=kimai@example.com
    volumes:
      - public:/opt/kimai/public
      # - var:/opt/kimai/var
      # - ./ldap.conf:/etc/openldap/ldap.conf:z
      # - ./ROOT-CA.pem:/etc/ssl/certs/ROOT-CA.pem:z
    restart: unless-stopped
  1. Check the Kimai container logs for errors like this:

[24-Jun-2023 19:20:37] NOTICE: PHP message: PHP Warning: Failed to set memory limit to 500 bytes (Current memory usage is 2097152 bytes) in Unknown on line 0

18:20:37 CRITICAL [php] Fatal Error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 36864 bytes) ["exception" => Symfony\Component\ErrorHandler\Error\OutOfMemoryError { …}]

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 36864 bytes) in /opt/kimai/vendor/twig/twig/src/TokenStream.php on line 41

Server:

Command used to run the container I turned the compose file into an Ansible role, so please excuse the added layer of abstraction and different syntax, but the variable names should be straight forward, and the relevant line is not affected by my changes.

- name: Start kimai2
  docker_container:
    name: kimai2
    image: "{{ kimai_image }}"
    state: started
    hostname: kimai # The nginx reverse proxy is hardcoded to look for host 'kimai'
    recreate: yes
    restart_policy: unless-stopped
    env:
      ADMINMAIL: "{{ ADMINMAIL }}"
      ADMINPASS: "{{ ADMINPASS }}"
      DATABASE_URL: 'mysql://{{ MYSQL_USER }}:{{ MYSQL_PASSWORD }}@kimai2_mysql/{{ MYSQL_DATABASE }}'
      TRUSTED_HOSTS: 'nginx,localhost,127.0.0.1'
      memory_limit: '500'
      MAILER_URL: "{{ MAILER_URL }}"
      MAILER_FROM: "{{ MAILER_FROM }}"
    mounts:
      - source: "{{ kimai_host_dir }}"
        target: /opt/kimai/public
        type: bind
    networks:
      - name: "{{ network }}"

Personal message Thank you to tobybatch and kevinpapst for all the time and effort going into this project. Awesome open source!

kevinpapst commented 1 year ago

Thanks for your words 👍

Would you send a PR to fix the issue?

tobybatch commented 1 year ago

I just fixed it