immich-app / immich

High performance self-hosted photo and video management solution.
https://immich.app
GNU Affero General Public License v3.0
52.42k stars 2.78k forks source link

Unable to run job handler (thumbnailGeneration/generate-person-thumbnail): Error: extract_area: bad extract area #12530

Open zero-thermo opened 2 months ago

zero-thermo commented 2 months ago

The bug

Initial set up of a new Immich v1.114.0 instance that uses read-only external libraries. All jobs completed, but saw several cases of the same error in logs.

What's going on and how do I resolve?

The OS that Immich Server is running on

Ubuntu 22.04.4 LTS

Version of Immich Server

v1.114.0

Version of Immich Mobile App

1.113.1 build.172

Platform with the issue

Your docker-compose.yml content

version: "3.8"

#
# WARNING: Make sure to use the docker-compose.yml of the current release:
#
# https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml
#
# The compose file on main may not be compatible with the latest release.
#

name: immich

services:
  immich-server:
    container_name: immich_server
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    # extends:
    #   file: hwaccel.transcoding.yml
    #   service: cpu # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl] for accelerated transcoding
    volumes:
      # Do not edit the next line. If you want to change the media storage location on your system, edit the value of UPLOAD_LOCATION in the .env file
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - ${EXTERNAL_PATH}:/usr/src/app/external:ro
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    ports:
      - 2283:3001
    depends_on:
      - redis
      - database
    restart: always
    healthcheck:
      disable: false

  immich-machine-learning:
    container_name: immich_machine_learning
    # For hardware acceleration, add one of -[armnn, cuda, openvino] to the image tag.
    # Example tag: ${IMMICH_VERSION:-release}-cuda
    image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release}
    # extends: # uncomment this section for hardware acceleration - see https://immich.app/docs/features/ml-hardware-acceleration
    #   file: hwaccel.ml.yml
    #   service: cpu # set to one of [armnn, cuda, openvino, openvino-wsl] for accelerated inference - use the `-wsl` version for WSL2 where applicable
    volumes:
      - model-cache:/cache
    env_file:
      - .env
    restart: always
    healthcheck:
      disable: false

  redis:
    container_name: immich_redis
    image: docker.io/redis:6.2-alpine@sha256:2d1463258f2764328496376f5d965f20c6a67f66ea2b06dc42af351f75248792
    healthcheck:
      test: redis-cli ping || exit 1
    restart: always

  database:
    container_name: immich_postgres
    image: docker.io/tensorchord/pgvecto-rs:pg14-v0.2.0@sha256:90724186f0a3517cf6914295b5ab410db9ce23190a2d9d0b9dd6463e3fa298f0
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
      POSTGRES_INITDB_ARGS: '--data-checksums'
    volumes:
      # Do not edit the next line. If you want to change the database storage location on your system, edit the value of DB_DATA_LOCATION in the .env file
      - ${DB_DATA_LOCATION}:/var/lib/postgresql/data
    healthcheck:
      test: pg_isready --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' || exit 1; Chksum="$$(psql --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' --tuples-only --no-align --command='SELECT COALESCE(SUM(checksum_failures), 0) FROM pg_stat_database')"; echo "checksum failure count is $$Chksum"; [ "$$Chksum" = '0' ] || exit 1
      interval: 5m
      # start_interval: 30s
      start_period: 5m
    command: ["postgres", "-c", "shared_preload_libraries=vectors.so", "-c", 'search_path="$$user", public, vectors', "-c", "logging_collector=on", "-c", "max_wal_size=2GB", "-c", "shared_buffers=512MB", "-c", "wal_compression=on"]
    restart: always

volumes:
  model-cache:

Your .env content

# You can find documentation for all the supported env variables at https://immich.app/docs/install/environment-variables

# The location where your uploaded files are stored
UPLOAD_LOCATION=/immich

# External Libraries
EXTERNAL_PATH=/photos

# The location where your database files are stored
DB_DATA_LOCATION=./postgres

# To set a timezone, uncomment the next line and change Etc/UTC to a TZ identifier from this list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
# TZ=Etc/UTC

# The Immich version to use. You can pin this to a specific version like "v1.71.0"
IMMICH_VERSION=release

# Connection secret for postgres. You should change it to a random password
# Please use only the characters `A-Za-z0-9`, without special characters or spaces
DB_PASSWORD=password

# The values below this line do not need to be changed
###################################################################################
DB_USERNAME=user
DB_DATABASE_NAME=db

Reproduction steps

  1. Setup Immich using standard docker-compose
  2. Add external libraries and Force Re-scan All Library Files
  3. Wait for all jobs to complete

OBSERVED: errors in logs

EXPECTED: no errors in logs

Relevant log output

[Nest] 6  - 09/10/2024, 12:18:01 AM   ERROR [Microservices:JobService] Unable to run job handler (thumbnailGeneration/generate-person-thumbnail): Error: extract_area: bad extract area
[Nest] 6  - 09/10/2024, 12:18:01 AM   ERROR [Microservices:JobService] Error: extract_area: bad extract area
    at Sharp.toFile (/usr/src/app/node_modules/sharp/lib/output.js:90:19)
    at MediaRepository.generateThumbnail (/usr/src/app/dist/repositories/media.repository.js:69:14)
    at PersonService.handleGeneratePersonThumbnail (/usr/src/app/dist/services/person.service.js:453:36)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /usr/src/app/dist/services/job.service.js:148:36
    at async Worker.processJob (/usr/src/app/node_modules/bullmq/dist/cjs/classes/worker.js:394:28)
    at async Worker.retryIfFailed (/usr/src/app/node_modules/bullmq/dist/cjs/classes/worker.js:581:24)
[Nest] 6  - 09/10/2024, 12:18:01 AM   ERROR [Microservices:JobService] Object:
{
  "id": "271ec018-81ea-4244-a1e1-1ec3cd86b50b"
}

Additional information

No response

mertalev commented 2 months ago

Do you have face importing enabled in the metadata settings? I don't think it handles orientation correctly at the moment.

zero-thermo commented 2 months ago

Do you have face importing enabled in the metadata settings? I don't think it handles orientation correctly at the moment.

Nope. Face Importing is left in its default off state in Metadata Settings.

mertalev commented 2 months ago

Could you open a random photo in your library, replace the ID in the URL with 271ec018-81ea-4244-a1e1-1ec3cd86b50b and open that? It'd be great if you could share this image (or another image that causes this error) so I can try to reproduce the issue.

zero-thermo commented 2 months ago

When I replace the ID (everything after https://.../photos/) of a random photo with 271ec018-81ea-4244-a1e1-1ec3cd86b50b and open, I get the following error in the WebUI:

Not found or no asset.read access (400)
Stacktrace

le@https://immich.mydomain.com/_app/immutable/chunks/fetch-client.Ce0fSmw3.js:1:2948
he@https://immich.mydomain.com/_app/immutable/chunks/fetch-client.Ce0fSmw3.js:1:2872
mertalev commented 2 months ago

Oh, the ID for this job is for a person, not an asset. Could you share the output of this one-liner? It assumes your DB username is user and the database is db, as in your .env file.

docker exec immich_postgres psql -U user -c "SELECT jsonb_pretty(jsonb_build_object('id', a.id, 'type', a.type, 'exifOrientation', e.orientation, 'exifHeight', e.\"exifImageHeight\", 'exifWidth', e.\"exifImageWidth\", 'previewHeight', af.\"imageHeight\", 'previewWidth', af.\"imageWidth\", 'originalPath', a.\"originalPath\", 'previewPath', file.path, 'personThumbnailPath', p.\"thumbnailPath\", 'x1', af.\"boundingBoxX1\", 'y1', af.\"boundingBoxY1\", 'x2', af.\"boundingBoxX2\", 'y2', af.\"boundingBoxY2\")) as metadata FROM assets a INNER JOIN exif e ON a.id = e.\"assetId\" INNER JOIN asset_faces af on a.id = af.\"assetId\" INNER JOIN person p on af.id = p.\"faceAssetId\" INNER JOIN asset_files file ON file.\"assetId\" = af.\"assetId\" AND file.type = 'preview' WHERE p.id = '271ec018-81ea-4244-a1e1-1ec3cd86b50b';" db
zero-thermo commented 2 months ago

Please see below for the output. File path redacted for privacy.

                                                             metadata                                                             
----------------------------------------------------------------------------------------------------------------------------------
 {                                                                                                                               +
     "id": "d3fbbb4d-2f45-42b2-a85f-3342bab4cfce",                                                                               +
     "x1": 1385,                                                                                                                 +
     "x2": 1481,                                                                                                                 +
     "y1": 1310,                                                                                                                 +
     "y2": 1435,                                                                                                                 +
     "type": "IMAGE",                                                                                                            +
     "exifWidth": 6112,                                                                                                          +
     "exifHeight": 4064,                                                                                                         +
     "previewPath": "upload/thumbs/4ec16a6d-2370-47ba-a52f-a71ae1b66971/d3/fb/d3fbbb4d-2f45-42b2-a85f-3342bab4cfce-preview.jpeg",+
     "originalPath": "/usr/src/app/external/Photography/<redacted>/IMG3497.DNG",            +
     "previewWidth": 2154,                                                                                                       +
     "previewHeight": 1440,                                                                                                      +
     "exifOrientation": "1",                                                                                                     +
     "personThumbnailPath": ""                                                                                                   +
 }
(1 row)
mertalev commented 2 months ago

Thanks, this is helpful. I'll try to reproduce the issue based on the dimensions and coordinates here.

zynexiz commented 2 months ago

Not sure if it's related, but I had issues with generating thumbs for some people to. Seems like it was related to NEF (Nikon RAW) files. When downloading the generated preview and uploaded it as a separate file, I could tag the person with that image. Seems like it fails with NEF files.

C-Otto commented 1 month ago

Similar to #13049 (wrong image size is used as the base for cropping)?