mealie-recipes / mealie

Mealie is a self hosted recipe manager and meal planner with a RestAPI backend and a reactive frontend application built in Vue for a pleasant user experience for the whole family. Easily add recipes into your database by providing the url and mealie will automatically import the relevant data or add a family recipe with the UI editor
https://docs.mealie.io
GNU Affero General Public License v3.0
5.74k stars 624 forks source link

[BUG] - Uploading an image crashes Mealie instantly #3848

Open felixschndr opened 2 weeks ago

felixschndr commented 2 weeks ago

First Check

What is the issue you are experiencing?

If I upload an image to a recipe Mealie instantly crashes.

This only seems to happen with images from my camera. Uploading an Android screenshot works without any issues. I guess there is some metadata in the images from my camera or the resolution brings Mealie to a halt.

Steps to Reproduce

  1. Create a recipe
  2. Add this image to the recipe: foto_no_exif (1)
  3. See mealie crash

Please provide relevant logs

These are the only logs (level set to DEBUG):

mealie_database   | 2024-07-04 20:44:55.714 UTC [636] LOG:  unexpected EOF on client connection with an open transaction
mealie_app exited with code 0

Mealie Version

Version: v1.10.1 (happend with 1.8.1 as well) Build: d639d168fa7c39ffb802d46ba05e4ec4de33faf9

Deployment

Docker (Linux)

Additional Deployment Details

No response

felixschndr commented 2 weeks ago

Edit: It was not a problem with the EXIF metadata of the file. I used an online tool to remove it and the bug still occured. It seems to be a problem with the size or resolution. The original image has a resolution of 4000x3000. After I cropped it a little (to 3795x2065) the bug does not appear any more

boc-the-git commented 2 days ago

Please share your docker-compose file.

Can this be replicated on an installation using our sample postgres docker-compose?

boc-the-git commented 2 days ago

You've said this can be replicated on the demo, what are the exact steps for that? This is the demo instance: image

felixschndr commented 1 day ago

Please share your docker-compose file.

services:
  mealie:
    image: ghcr.io/mealie-recipes/mealie
    container_name: mealie_app
    ports:
        - 12000:9000
    deploy:
      resources:
        limits:
          memory: 400M
    volumes:
      - ./data/mealie:/app/data/
    environment:
      ALLOW_SIGNUP: "false"
      PUID: ${ENV_PUID}
      PGID: ${ENV_PGID}
      TZ: ${TIMEZONE}
      API_DOCS: "false"
      MAX_WORKERS: 1
      WEB_CONCURRENCY: 1
      DB_ENGINE: postgres
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_SERVER: mealie_database
      POSTGRES_PORT: 5432
      POSTGRES_DB: ${POSTGRES_DB}
      SMTP_HOST: ${SMTP_HOST}
      SMTP_PORT: ${SMTP_PORT}
      SMTP_FROM_NAME: ${SMTP_FROM_NAME}
      SMTP_AUTH_STRATEGY: ${SMTP_AUTH_STRATEGY}
      SMTP_FROM_EMAIL: ${SMTP_FROM_EMAIL}
      SMTP_USER: ${SMTP_USER}
      SMTP_PASSWORD: ${SMTP_PASSWORD}
    restart: always
    depends_on:
      - database
  database:
    container_name: mealie_database
    image: postgres:15
    volumes:
      - ./data/postgres/postgres:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    restart: always
    healthcheck:
      test: pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB
      interval: 5s
      timeout: 5s
      retries: 5

You've said this can be replicated on the demo, what are the exact steps for that?

I just tried this on my personal mealie instance. The steps are as follows

  1. Download the image from above (normal right click and save)
  2. Create a new recipe
  3. Add the image (via upload)
  4. See mealie crash in the logs

This is with the newest available docker version (Version v1.10.2, Build e344f3f1e6672d673f6e0899a5cef28aa8beb2f0.

I just tried it again in the demo instance and was not able to reproduce it. However I am pretty sure I was able to reproduce it in the demo instance in the past.

felixschndr commented 1 day ago

I made you a screen recording (maybe it helps). You can find it here

boc-the-git commented 1 day ago

@felixschndr can you post your compose file with code formatting.

It
Should
Look
Something like this

It's not really readable in its current state.

One initial suggestion, try increasing the memory limit, at least to 1000

felixschndr commented 1 day ago

can you post your compose file with code formatting.

Yes, of course. I tried doing a summary but that messed up the formatting. I changed the original post.


try increasing the memory limit, at least to 1000

That fixed the issue. Thanks. However I am wondering about two things

  1. Why does Mealie need that much RAM to work with the image?
  2. Maybe Mealie could throw some kind of exception when it recognizes it runs out of memory. I don't know if this is possible. There should be a MemoryError https://docs.python.org/3/library/exceptions.html#MemoryError
felixschndr commented 1 day ago

I checked the memory usage of the container. In idle it needs about 380 MB. While adding the image it needs 550 MB (170MB more for an 7 MB image). After adding the image the container needs 430 MB