immich icon indicating copy to clipboard operation
immich copied to clipboard

Automatic local URL switching frequently fails

Open ShawnTheBeachy opened this issue 10 months ago • 10 comments

The bug

I have automatic URL switching set up when I am on my home network. I have the following setup:

External network: Only one entry: my externally accessible URL. Local network: My Wi-Fi name and local URL

I'm not able to reproduce it reliably, but probably 8 times out of 10 when I open the iOS app not on my local network, it still tries to use the local URL. Restarting the app usually switches it to the remote URL.

The OS that Immich Server is running on

Docker on Windows

Version of Immich Server

v1.124.2

Version of Immich Mobile App

v1.124.0 build.187

Platform with the issue

  • [ ] Server
  • [ ] Web
  • [X] Mobile

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}
    extends:
      file: hwaccel.transcoding.yml
      service: nvenc
    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
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    ports:
      - '2283:2283'
    depends_on:
      - redis
      - database
    restart: always
    healthcheck:
      disable: false

  immich-machine-learning:
    container_name: immich_machine_learning
    image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release}-cuda
    extends:
      file: hwaccel.ml.yml
      service: cuda
    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:eaba718fecd1196d88533de7ba49bf903ad33664a92debb24660a922ecd9cac8
    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
    ports:
      - '127.0.0.1:5435:5432'
    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=D:/immich/uploads
# The location where your database files are stored
DB_DATA_LOCATION=D:/immich/.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/US

# 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=******

# The values below this line do not need to be changed
###################################################################################
DB_USERNAME=postgres
DB_DATABASE_NAME=immich

Reproduction steps

  1. Open the app off my local network.
  2. Notice that Immich can't connect to the server. Check the URL, see that it is trying to use the local URL.
  3. Reopen the app. Check the URL, see that it is (usually) fixed. Repeat step 3 if not.

Relevant log output

No response

Additional information

Immich's "Location" permissions are set to Always.

ShawnTheBeachy avatar Jan 10 '25 15:01 ShawnTheBeachy

when I open the iOS app not on my local network

Do you know if this is happening when you are on mobile data or on a different WIFI network?

alextran1502 avatar Jan 10 '25 15:01 alextran1502

@alextran1502 It happens both ways. The other day I had it happen on mobile data, and today I had it happen while on my work Wi-Fi. Wish I could give more info, but I can't seem to reproduce it reliably...

ShawnTheBeachy avatar Jan 10 '25 16:01 ShawnTheBeachy

Thanks, I will investigate this

alextran1502 avatar Jan 10 '25 16:01 alextran1502

@alextran1502 Not sure if this is helpful, but I just noticed it actually goes the other way, too. I just opened Immich on my local network, and it continued using the remote URL until an app restart.

ShawnTheBeachy avatar Jan 11 '25 01:01 ShawnTheBeachy

@ShawnTheBeachy can you let me know where do you confirm the connection info?

alextran1502 avatar Jan 11 '25 02:01 alextran1502

@alextran1502 I'm tapping on my profile photo in the top right corner and checking the "Server URL" in the popup.

ShawnTheBeachy avatar Jan 11 '25 02:01 ShawnTheBeachy

Ah that is not necessarily reflecting the correct info. There is a caching bug of showing the value. However, it is using the correct url

alextran1502 avatar Jan 11 '25 02:01 alextran1502

@alextran1502 Ah I see! Perhaps there’s overlap with some other bug, then? I just encountered this issue again and I did some testing; the app was non-functional until I did a restart and it showed the correct (remote) URL. Any attempts to refresh the library, view albums, search, etc. just showed a spinner indefinitely. I also checked the logs, and it did say “Resuming session at [my local URL]” even though I wasn’t on my Wi-Fi.

EDIT: Looking at the logs more, it does actually look like the sync was succeeding, though. Perhaps some parts of the UI just aren’t using the correct URL or something…?

ShawnTheBeachy avatar Jan 11 '25 13:01 ShawnTheBeachy

Same for Android phones. I think the URL switch doesn't work. If I turn off the WiFi and refresh (pulling down the screen), it takes forever. But if I close the app and open it again, it works perfectly with 5G (but on then URL server shows a local IP).

pablodre avatar Jan 31 '25 10:01 pablodre

I could actually troubleshoot this to some extent, but I didn't check the iOS mobile app codes.

It seems like this feature actually works. It understood my new local IP address value and also forwarded the requests accordingly. It is visible on the logs however there is an interesting Socket operation failed error message here.

As you can see in the following error message the address 192.168.50.103 is correct however the port 61701 is not correct at all. the URI has the correct 2283 port definition tho. ( a fun fact here, this is actually a full URL, not a URI ) Maybe the mobile app confused some parameters and it is not correctly setting the port and URI variables.

PlatformDispatcher - Catch all

ApiException 400: Socket operation failed: GET /partners (Inner exception: ClientException with SocketException: Connection refused (OS Error: Connection refused, errno = 61), address = 192.168.50.103, port = 61701, uri=http://192.168.50.103:2283/api/partners?direction=shared-by)

#0      IOClient.send (package:http/src/io_client.dart:154)
<asynchronous suspension>
#1      BaseClient._sendUnstreamed (package:http/src/base_client.dart:93)
<asynchronous suspension>
#2      ApiClient.invokeAPI (package:openapi/api_client.dart:101)
<asynchronous suspension>
#3      PartnersApi.getPartners (package:openapi/api/partners_api.dart:102)
<asynchronous suspension>
#4      ApiRepository.checkNull (package:immich_mobile/repositories/api.repository.dart:5)
<asynchronous suspension>
#5      PartnerApiRepository.getAll (package:immich_mobile/repositories/partner_api.repository.dart:22)
<asynchronous suspension>
#6      UserService.getUsersFromServer (package:immich_mobile/services/user.service.dart:63)
<asynchronous suspension>
#7      UserService.refreshUsers (package:immich_mobile/services/user.service.dart:102)
<asynchronous suspension>
#8      AlbumService.refreshRemoteAlbums (package:immich_mobile/services/album.service.dart:172)
<asynchronous suspension>
#9      AlbumNotifier.refreshRemoteAlbums (package:immich_mobile/providers/album/album.provider.dart:31)
<asynchronous suspension>

DorukAkinci avatar Feb 27 '25 10:02 DorukAkinci

Same issue here on Oneplus 12 and Galaxy S24 Ultra.

App does not recognize the switch itself. If I log on through my external IP (through tailscale) outside of my home it connects. But when I come home and connect to wifi it doesn't make the switch itself and stays on external IP and thus no connection at all.

Halle914 avatar Mar 27 '25 15:03 Halle914

@Halle914 Do you have multiple WIFI names on your network?

alextran1502 avatar Mar 27 '25 16:03 alextran1502

@Halle914 Do you have multiple WIFI names on your network?

I do, the following names:

DG72-5 (5Ghz) DG72 (2,4 Ghz)

Both networks are hidden. But both phones autoconnect to 5Ghz one and are not connect to the other.

Is that an issue?

Halle914 avatar Mar 27 '25 17:03 Halle914

@Halle914, just make sure that the network the phone is connecting to has the same WiFi name as that specified in the Immich app.

alextran1502 avatar Mar 27 '25 17:03 alextran1502

@Halle914, just make sure that the network the phone is connecting to has the same WiFi name as that specified in the Immich app.

It has, on both phones. But when it connects to my external IP it don't connect back. That's my issue right now.

Halle914 avatar Mar 27 '25 17:03 Halle914

Found a goofy workaround. i keep getting the wifi could not be found error regardless of wifi name, name spaces, name case etc. So i left the info for the wifi with the local http://ip:port in the local network settings, then added my domain access config in the external network settings and then added my local http://ip:port config in the external settings above the domain settings. when im on the wifi at home, device can see that ip and defaults to the local ip setup and when im external to the network the devices jumps down the list and hits the domain config and it accesses that way. Unsure if there is any security risk here but id imagine since its not a publicly routable ip for the internal its not really giving away much info. Correct me if im wrong though!

Still kinda funky on the application though. Have to force stop when i switch to wifi and then start app again. Sometimes the backup settings reset. Kinda works, kinda doesnt.

nagasaki23 avatar Apr 07 '25 23:04 nagasaki23

I have the same issue but the other away around. The app always connects via the public endpoint and completely ignores my local endpoint when I'm in the configured wifi. The switch worked exactly one time after I set it up, but after it switched back to the public endpoint it never switched to the local ever again. At least it always shows the same active endpoint in the app, but maybe I'm affected by the caching issue? https://github.com/immich-app/immich/issues/15220#issuecomment-2585029956

kimdre avatar Apr 29 '25 09:04 kimdre

I got issue as well with this functionality. In the last couple of weeks my network setting remains on local ip address even if I am away from home and related known wifi. I tried to kill and restart manually, but still does not switch h to remote server URL. I checked all permissions of the app and nothing changed, they're still correct. I am running on Android.

EDIT: checking logs I saw that was depending on a validation issue of the server certificate. Fixing it now is working properly again.

FerrMattDev avatar May 04 '25 08:05 FerrMattDev

For me it is switching properly but only when I clear my app from memory and restart. If while in the app I toggle wifi on and then off or vise versa it will not change dynamically. I need to exit the app from memory and then restart.

So the switching is working properly, it's just not switching until I restart the app.

Edit: Unless it is actually switching but the displayed "Current Server Address" is not refreshing. That could be a possibility.

dcuellar avatar May 31 '25 19:05 dcuellar

I had the same problem, but the fault were my own. I use Cloudflare and custom headers for the app. The custom headers expired so the change did not happen when I turned off the Wifi. Stupid mistake :)

radhoo2k10 avatar Jun 01 '25 15:06 radhoo2k10

Exactly the same problem. Immich accessed externally through CF tunnel and zero trust. Custom headers in the web app. Auto URL change configured. If I'm in external, and get into home and get WiFi, URL doesn't change. 100mb limit of CF don't letting things to upload. I close the app, restart it and the WiFi starts working. Sometimes restart 2 times. Current server address not refreshing. And then works.Android. latest immich 1.142.0..

dalekhog avatar Sep 14 '25 00:09 dalekhog

The switching not working for me at all UNLESS I set my Immich IP address under the external network section and place it on the top, above my external web address. Of course the WiFi network name and the Immich IP address is also set in the local network section.

godzinilla avatar Oct 07 '25 22:10 godzinilla