immich-app / immich

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

[BUG] EntityNotFoundError: Could not find any entity of type "AssetEntity" matching #1122

Closed xxyzz closed 1 year ago

xxyzz commented 1 year ago

Describe the bug I use the IOS app to backup photo but the app stuck at 154 assets, then I check the "immich-app_immich-server_1" container log and find many "EntityNotFoundError":

EntityNotFoundError: Could not find any entity of type "AssetEntity" matching:
    "where": {
        "userId": "x",
        "checksum": {
            "type": "Buffer",
             "data": [
                235,
                5,
                134,
                1,              
                233,
                113,            
                9,              
                187,            
                112,
                101,
                218,            
                118,            
                219,         
                120,
                148,
                110,
                80,
                62,
                10,
                59
            ]
        }
    },
    "relations": [
        "exifInfo"
    ]
}
    at /usr/src/app/node_modules/typeorm/entity-manager/EntityManager.js:590:39
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async AssetService.handleUploadedAsset (/usr/src/app/dist/apps/immich/apps/immich/src/api-v1/asset/asset.service.js:95:38)

And the "immich_postgres" container log has many duplicate key errors:

2022-12-19 07:09:31.441 UTC [66] ERROR:  duplicate key value violates unique constraint "UQ_userid_checksum"
2022-12-19 07:09:31.441 UTC [66] DETAIL:  Key ("userId", checksum)=(543e65cc-5df3-47f6-80bc-0110c0c195c8, \xebd2cfb5386e7cfca3016e6ef6ebf6851fa57544) already exists.
2022-12-19 07:09:31.441 UTC [66] STATEMENT:  INSERT INTO "assets"("id", "deviceAssetId", "userId", "deviceId", "type", "originalPath", "resizePath", "webpPath", "encodedVideoPath", "createdAt", "modifiedAt", "isFavorite", "mimeType", "checksum", "duration", "isVisible", "livePhotoVideoId") VALUES (DEFAULT, $1, $2, $3, $4, $5, DEFAULT, DEFAULT, DEFAULT, $6, $7, $8, $9, $10, $11, $12, $13) RETURNING "id", "webpPath", "encodedVideoPath", "isFavorite", "isVisible"

I didn't changed the docker-compose file and I only change the UPLOAD_LOCATION and JWT_SECRET variables in .env file. Before backup file on my phone, I used the cli to upload some files and one file got 504 error then I rerun the command it was uploaded successfully.

Server OS: Arch Linux Podman version: 4.3.1

Task List

Please complete the task list below. We need this information to help us reproduce the bug or point out problems in your setup. You are not providing enough info may delay our effort to help you.

To Reproduce Steps to reproduce the behavior:

  1. Use immich cli to upload some files.
  2. Backup photos from phone.

Expected behavior Backup all photos.

Screenshots

System

Additional context Add any other context about the problem here.

bo0tzz commented 1 year ago

It seems like you're on a very old version of Immich. Please update both the server and the app.

xxyzz commented 1 year ago

Oh I type the wrong version number... I'm using the latest version.

alextran1502 commented 1 year ago

If you restart the upload, would it still get stuck at that specific file? Are you accesing Immich through your local IP or through a reverse proxy?

The duplication error can be ignored assuming that the files you uploaded from the CLI are the exact same files from your phone, or you have duplicated files when uploading from either the CLI or your phone.

The AssetEntity not found perhaps not related to the issue you are facing, can you try uploading again while looking at the server log to make sure the timestamp of the log matches the upload operation

xxyzz commented 1 year ago

The remainder assets number is always 154 and the uploading file info stops at the same file. I have some photos backed up by Nextcloud before, but Nextcloud breaks the HEIC file to jpeg and mov file. I add those Nextcloud photos via the immch cli command before using the app, maybe the server think they are the same but not the app?

I access immich though local IP.

I'm still seeing the same errors in the logs.

alextran1502 commented 1 year ago

@xxyzz Hmm, Immich handles LivePhotos by uploading the HEIC and the MOV portion to the server. I think this might conflict with the MOV files you are backing up from NextCloud.

Can you help me test the hypothesis by creating a new instance, then uploading the photos from your mobile phone before running the CLI?

alextran1502 commented 1 year ago

Note for me. This might be the source of the problem. There is no catch block for this awaiting call. Ideally, this should not fail because there is a duplicated with the same hash

https://github.com/immich-app/immich/blob/8998a79ff9c33bd71d7c81107874bb6a7a845d22/server/apps/immich/src/api-v1/asset/asset.service.ts#L171-L175

xxyzz commented 1 year ago

I delete those jpeg and mov files from immich's web page and the app uploads all the photos successfully. I'm pretty sure the Nextcloud's mov files cause the error. I'll consider the issue resolved since it's caused by previous backup files from Nextcloud.

xxyzz commented 1 year ago

~I find another bug in the app. Click a thumbnail then swift to the right from the left of the screen to return to the grid view. The app will turn to a black screen when I repeat this the third time.~

Please ignore this comment, I can't reproduce this anymore.

And thank you for maintaining this amazing project, keep up the good work!

JustAmply commented 1 year ago

I've got the same issue after importing (around 150.000) images from my nextcloud library via the cli tool. Already imported images are stuck in the upload queue of the iOS app. They are repeatedly being uploaded, as they don't get marked as a duplicate when the error is thrown.

gemagomez commented 1 year ago

We've seen this same issue as well, but with a regular import from the iOS app, on a freshly installed v1.50.1 server. It happened when the microservices container (I believe) was OOM killed. Immich doesn't seem to cope too gracefully with temporary failures, and that seems to result in corruption in the database vs filesystem/object storage.

SMAW commented 1 year ago

Having the same issue also, cannot even delete pictures anymore on webpage. Also the pictures that aren't uploaded yet, because of the error are not visable...