immich-app / immich

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

Android app freezing after launch #10030

Open matejkramny opened 5 months ago

matejkramny commented 5 months ago

The bug

The android app freezes shortly after launching, every time. Perhaps I have too big of a library.. web works fine. The app logs don't show anything useful.

I have tested the demo server, and it works fine. Library is ~70k photos. Another user on my server has ~10k photos - works without issue.

Have had an external library but removed since, don't think it's a duplicate of #8148 but is very similar.

How can I best figure out what's wrong?

The OS that Immich Server is running on

Ubuntu 22 lts

Version of Immich Server

1.105.1

Version of Immich Mobile App

1.105.1

Platform with the issue

Your docker-compose.yml content

#
# 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}
    command: ['start.sh', 'immich']
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    ports:
      - 2283:3001
    depends_on:
      - redis
      - database
    restart: always
  immich-microservices:
    container_name: immich_microservices
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    # extends: # uncomment this section for hardware acceleration - see https://immich.app/docs/features/hardware-transcoding
    #   file: hwaccel.transcoding.yml
    #   service: cpu # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl] for accelerated transcoding
    command: ['start.sh', 'microservices']
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    depends_on:
      - redis
      - database
    restart: always
  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
  redis:
    container_name: immich_redis
    image: registry.hub.docker.com/library/redis:6.2-alpine@sha256:84882e87b54734154586e5f8abd4dce69fe7311315e2fc6d67c29614c8de2672
    restart: always
  database:
    container_name: immich_postgres
    image: registry.hub.docker.com/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:
      - ${DB_DATA_LOCATION}:/var/lib/postgresql/data
    restart: always
    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"]
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=<redacted>
# The location where your database files are stored
DB_DATA_LOCATION=<redacted>
# 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
DB_PASSWORD=<redacted>
# The values below this line do not need to be changed
###################################################################################
DB_USERNAME=<redacted>
DB_DATABASE_NAME=<redacted>

Reproduction steps

1. Have big library
2. open android client (logged in already)
3. App is interactive for ~10s
4. App freezes, perhaps for ~30s
5. Becomes responsive again but then freezes forever
6. Backgrounding and opening app then shows black screen (flutter crashed perhaps)
...

Relevant log output

I can't find any relevant logs in the app
Have enabled more verbose + diagnostics. No logs after the black screen

Additional information

The top user is not working, bottom one has no problems Screenshot_20240607-205352~2

alextran1502 commented 5 months ago

Can you try accessing your instance over local IP? What is your mobile phone model?

matejkramny commented 5 months ago

Hi, I can't as it's a dedicated server in another country. Using pixel 2 (android 11). It's understandably not the best in today's performance but it works just fine with 10k photos user

Mikesco3 commented 5 months ago

I'm having the same issue. My server is within my local network, I'm accessing it using the local static IP.

I'm running a galaxy S21+

But it seems to be the issue with my android app version 1.106.3 build 14.3

Server version 1.106.4 on a Debian 12 container.

The experience is that:

  1. Open the app
  2. If I scroll a bit or try to play a video, then at around 30 seconds into it, the app freezes and doesn't respond to anything, except if I hit the button on my phone to switch to another app, (not even backing all the way out to another app, just enough to show me the carousel of other running apps) and then go back to Immich then it might snap out of it after about a 3-5 second blank screen but about 10 - 30 seconds later lock up again.
  3. But most of the time I can only get it back by closing Immich and starting again.

I've tried running it in various conditions: Closing all other apps Rebooting the phone But same result, seems to be pretty consistent.

It feels like it locks up trying to index or cash the content.

I also very large library. Also the app doesn't tell me anymore how many total items...

Let me know how else I can help. Thank you for such an awesome app!! Look Forward to contributing and paying some

matejkramny commented 5 months ago

I'm going to try to attach adb to the app loaded on my phone and will see what's locking it up later this week. Can't reproduce the hanging in the emulators but I'm suspecting it's writing a lot of data to the database?

matejkramny commented 5 months ago

I wonder if it would be worth implementing this usage pattern, if not already - https://isar.dev/recipes/multi_isolate.html#example

I found isolate usage in the code but it might be for the background sync. I'm thinking if doing the database sync in an isolate thread would help with performance. For a large library I imagine 70k record updates would take a while whilst it freezes the UI thread

matejkramny commented 4 months ago

Hi,

I found using isolates helped, adb logs don't show any more than usual, other than using CPU profiling which shows Isar doing this:

image image image

The UI locks up at this state, and there are no more logs.

Doing more CPU profiling shows about the same things, maybe as flutter itself stops responding on the app. It's possible something crashes, but I'm at a loss as to how to debug it any further because there are no logs in addition to what I screenshotted.

As I mentioned, running the app with my isolate PR fixes this problem, but I suspect it might be something related to it, or a side effect/bug that I put in f.e. - there are watchers on the Isar db that would refresh the UI. Perhaps this happens too many times (per asset?) and that might/not be happening with the assets synced in the isolate?

Thank you!

AleXburnA commented 3 months ago

We‘re experiencing the same on my wife’s Galaxy S20, see here: https://github.com/immich-app/immich/discussions/9614 No problem on my iPhone

I hope your PR can be merged at some point. For us, this is the most annoying bug with this otherwise amazing software. I understood it might not be the root cause, but maybe it improves things. I am clutching at every straw 🤣

dsimoes commented 2 months ago

Hey!

I've implemented immich locally for a month now. Everthing has being going great up until a few days ago? For some reason the App opens, I can see the thumbnails loading and then It just hangs, can't scroll ou access the menus.

Android App version: 1.115.0 Immich version (updated today): v1.115.0 Phone: Samsung A53 5G

I've tried clearing cache: same behaviour. I've proceeded clearing data. This required me to login again and setup automatic backup. So far the app is working, will report back if not.

LinhyCZ commented 2 months ago

This is unfortunately also happening to me for couple of versions.. Background sync works, but after few (approximately 20) seconds the app freezes and I cannot do anything. Does not matter if I open gallery or sync settings, or other screen. If I tab out and return to app, I only see black screen.

Immich version (both app and server): 1.115.0 Phone: Huawei Mate 10 Pro

alextran1502 commented 2 months ago

@LinhyCZ how many assets do you have on your instance and local device? How many album do you have on your Immich instance? How long have you been installing the app?

matejkramny commented 2 months ago

@alextran1502 is there a good way to get library stats? I've made a dummy user with 100k photos and the app worked just fine. My library is ~70k + some videos

Also tested on pixel 2 when i made this issue (100% of the time), now got a pixel 8 pro - still having the same problem just not as frequently

alextran1502 commented 2 months ago

@matejkramny the easiest way is from the web, you can hover on the icon next to the navigation button to show how many assets/albums the user has. I believe the bottleneck is our albums synchronization code that competes with the UI thread. We discussed internally and come up with a better solution. The PRs you are seeing that refactoring the mobile app are steps toward solving this issue

LinhyCZ commented 2 months ago

@alextran1502 I have about 24k photos and 2k videos + 10k assests from external library. I have been using Immich for almost a year (I think :D), about two months ago I noticed some assets were not uploaded, so I uninstalled the app, installed it again and reran the upload job (which fixed the missing assets).

alextran1502 commented 2 months ago

@LinhyCZ thanks for the info. How many Immich's albums and albums on the local device do you have?

LinhyCZ commented 2 months ago

@alextran1502 I only clicked on the Recent option, I don't have any albums created..

LinhyCZ commented 1 month ago

@alextran1502 I have tried working with the app a bit more, uninstalled it and installed it back again and it is somewhat working, but the reactions are very slow.. sometimes it takes about 30 seconds until the app registers i clicked on something or renders something..

alextran1502 commented 1 month ago

@LinhyCZ We are working toward a better sync operation, which will make the app more responsive when first opening. By the way, what is your phone model?

LinhyCZ commented 1 month ago

@alextran1502 Might make it better, but this is not just on a first opening. For me the app is very sluggish the whole time I use it.

My phone is an old Huawei Mate 10 Pro.

yewkay commented 1 month ago

I have 63k photos and I'm experiencing the same app hang/crash issue. Background sync works but if I open the app, it will crash shortly.

Opening in webui will works fine for me

jetblack-nz commented 1 month ago

Hi, not sure this is supposed to be Android specific, just noting that I experience the same with 55k images on a new iPhone. The app freezes regularly after opening.

Matou25 commented 1 month ago

@alextran1502 Hi, I previously post in https://github.com/immich-app/immich/issues/11113#issuecomment-2384273824 but my issue is more this one . i have systematic crash of android app after around 24sec on huawei P30pro and S21+:

it work until i force app to close in android menu

alextran1502 commented 1 month ago

@Matou25 what is the stats of your account? How many assets, how many albums?

Matou25 commented 1 month ago

@alextran1502 image it's an external library for now 10 albums ( working on create more base on my folder tree)

ThomasConrad commented 1 month ago

Have the same issue with about 33k images. Have to force reboot entire phone to escape it. Android galaxy s20.

slagiewski commented 3 weeks ago

I have the same issues with about 50k images. Galaxy s20 fe

alextran1502 commented 3 weeks ago

@ThomasConrad @slagiewski Can you guys try not selecting any album for backup and open the app, so that it loads the remote only assets and see if it is still crashing

Matou25 commented 3 weeks ago

@ThomasConrad @slagiewski Can you guys try not selecting any album for backup and open the app, so that it loads the remote only assets and see if it is still crashing

Hi @alextran1502, To add information my account is admin account. I dont use backup function

alextran1502 commented 3 weeks ago

We are working on a better sync mechanism, which hopefully solves this issue #13699

Matou25 commented 1 week ago

I dont know if it can help, only graphic seem to crash. If I start a vidéo before the app crash(30s), sound is fine event after screen freeze, sound continue to play

matejkramny commented 1 week ago

Hi @alextran1502, the latest app update have made things a lot more stable, as in I am no longer seeing the app freezing and is much smoother than before. Running 1.20.1

I'm happy to close this issue but perhaps others who also experienced this can confirm it's gone too?

Matou25 commented 1 week ago

@matejkramny even with 1.120.1 build166 it's the same for me, app continue to freeze server is in 1.120.2

alextran1502 commented 1 week ago

There is nothing that changes @matejkramny. Perhaps you were connecting through the local IP so the sync process is faster?

LinhyCZ commented 1 week ago

Just to add some my recent findings - This happens only on my older phone Huawei Mate 10 Pro, my GF's Pixel 7 is working all good and she has huge (like 10x bigger than mine) library.

I've noticed, that I just have to sit through the sync at the beginning and after that it works great. It starts working after | INFO | AssetNotifier | Load assets: 186936ms | Appears in the log.

What is interesting to me (maybe it's fine, I have no clue how the sync process worked) is these lines in log 2024-10-01 16:39:43.004103 | INFO | SyncService | Added a new local album to DB: Camera | 2024-10-01 16:39:42.691853 | INFO | SyncService | Upserted 7025 assets into the DB | 2024-10-01 16:39:41.821461 | INFO | SyncService | 8 assets already existed in DB, to upsert 7025 | 2024-10-01 16:39:06.896311 | INFO | SyncService | Syncing a new local album to DB: Camera |

I used Immich multiple times before on my device. Why does it load all the images to DB again? (And takes over 30 seconds)

But again, maybe it should work like that and the only issue is the sync mechanism that is being worked on. (Thank you very much for that, btw :))