[BUG] Immich tries to connect with TCP when REDIS_SOCKET is provided #599

Closed
opened 2026-02-04 21:28:48 +03:00 by OVERLORD · 2 comments
Owner

Originally created by @JVT038 on GitHub (Jan 19, 2023).

Describe the bug
I have supplied the environment variables to use Redis with unix socket instead of TCP. The .env looks like this:

# REDIS_HOSTNAME=immich_redis
# Optional Redis settings:
# REDIS_PORT=6379
# REDIS_DBINDEX=0
REDIS_PASSWORD="a very long password"
REDIS_SOCKET=/sockets/immich_redis.sock

The REDIS_PORT and REDIS_HOSTNAME are commented out, so Immich shouldn't try to connect with those values.
However, it does.
It shows this in the docker-compose logs:

immich-server_1            | Error: connect ECONNREFUSED 192.168.64.3:6379
immich-server_1            |     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16)
immich-server_1            | Emitted 'error' event on Commander instance at:
immich-server_1            |     at RedisSocket.<anonymous> (/usr/src/app/node_modules/@redis/client/dist/lib/client/index.js:360:14)
immich-server_1            |     at RedisSocket.emit (node:events:527:28)
immich-server_1            |     at RedisSocket._RedisSocket_connect (/usr/src/app/node_modules/@redis/client/dist/lib/client/socket.js:153:18)
immich-server_1            |     at processTicksAndRejections (node:internal/process/task_queues:96:5)
immich-server_1            |     at async Commander.connect (/usr/src/app/node_modules/@redis/client/dist/lib/client/index.js:173:9)
immich-server_1            |     at async Promise.all (index 0)
immich-server_1            |     at async RedisIoAdapter.connectToRedis (/usr/src/app/dist/apps/immich/apps/immich/src/middlewares/redis-io.adapter.middleware.js:18:9)
immich-server_1            |     at async bootstrap (/usr/src/app/dist/apps/immich/apps/immich/src/main.js:31:5) {
immich-server_1            |   errno: -111,
immich-server_1            |   code: 'ECONNREFUSED',
immich-server_1            |   syscall: 'connect',
immich-server_1            |   address: '192.168.64.3',
immich-server_1            |   port: 6379
immich-server_1            | }

Additionally, it somehow manages to connect to the right IP address.
The internal IP of my Redis container is 192.168.64.3 and that's exactly what the server tries to connect to.
I have set the port to 0 in my redis configuration, so that it would block all TCP requests, but that gives this error.
Immich has never had a problem with my unix socket configuration up until the latest version v1.42.0, so I'm suspecting that that update has done something that broke my unix socket configuration.

I managed to temporarily resolve this by connecting over TCP instead of Unix, but I would like to be able to use an Unix socket, because the Unix sockets are faster than TCP.

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.

  • I have read thoroughly the README setup and installation instructions.
  • I have included my docker-compose file.
  • I have included my redacted .env file.
  • I have included information on my machine, and environment.

To Reproduce
Steps to reproduce the behavior:

  1. Set up Immich with Redis Unix socket connection
  2. Start the containers
  3. See error

Expected behavior
I expected Immich to connect with my Redis container over unix instead of TCP.

System

  • Phone OS [iOS, Android]: Android 12
  • Server Version: v1.42.0
  • Mobile App Version: v1.41.0

Additional context
I use a Traefik proxy to connect and don't use the Immich NGINX proxy container.
In case that matters, here is my docker-compose.yml

version: "3.8"

networks:
  traefik_proxy:
    external:
      name: traefik_proxy

services:
  immich-server:
    image: altran1502/immich-server:release
    entrypoint: ["/bin/sh", "./start-server.sh"]
    networks:
      - traefik_proxy
      - default
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - sockets:/sockets
    env_file:
      - .env
    environment:
      - NODE_ENV=production
    depends_on:
      - redis
      - database
    restart: always
    labels:
      traefik.enable: "true"
      traefik.docker.network: traefik_proxy
      traefik.http.services.immich-api-svc.loadbalancer.server.port: "3001"
      traefik.http.routers.immich-api-rtr.rule: "Host(`immich.$DOMAINNAME`) && Pathprefix(`/api`)"
      traefik.http.routers.immich-api-rtr.priority: 20
      traefik.http.middlewares.immich-api-strip.stripprefix.prefixes: "/api"
      traefik.http.routers.immich-api-rtr.middlewares: immich-api-strip,chain-basic@file
      traefik.http.routers.immich-api-rtr.service: immich-api-svc
      traefik.http.routers.immich-api-rtr.tls: true
      traefik.http.routers.immich-api-rtr.tls.certresolver: dns-cloudflare
      traefik.http.routers.immich-api-rtr.entrypoints: https

  immich-microservices:
    image: altran1502/immich-server:release
    entrypoint: ["/bin/sh", "./start-microservices.sh"]
    networks:
      - default
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - sockets:/sockets
    env_file:
      - .env
    environment:
      - NODE_ENV=production
    depends_on:
      - redis
      - database
    restart: always

  immich-machine-learning:
    build:
      context: $DOCKERDIR/immich/immich-ml
      dockerfile: Dockerfile
    entrypoint: ["/bin/sh", "./entrypoint.sh"]
    networks:
      - default
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
    env_file:
      - .env
    environment:
      - NODE_ENV=production
    depends_on:
      - database
    restart: always

  immich-web:
    image: altran1502/immich-web:release
    entrypoint: ["/bin/sh", "./entrypoint.sh"]
    networks:
      - default
      - traefik_proxy
    env_file:
      - .env
    restart: always
    labels:
      traefik.enable: "true"
      traefik.docker.network: traefik_proxy
      traefik.http.services.immich-svc.loadbalancer.server.port: "3000"
      traefik.http.routers.immich-rtr.rule: "Host(`immich.$DOMAINNAME`)"
      traefik.http.routers.immich-rtr.priority: 10
      traefik.http.routers.immich-rtr.service: immich-svc
      traefik.http.routers.immich-rtr.middlewares: chain-basic@file
      traefik.http.routers.immich-rtr.tls: true
      traefik.http.routers.immich-rtr.tls.certresolver: dns-cloudflare
      traefik.http.routers.immich-rtr.entrypoints: https

  redis:
    container_name: immich_redis
    image: redis:6.2
    restart: always
    networks:
      - default
    command: redis-server /etc/redis.conf
    volumes:
      - sockets:/sockets
      - $DOCKERDIR/immich/redis.conf:/etc/redis.conf
      - /etc/TZ:/etc/timezone:ro
      - $DOCKERDIR/immich/redisdb:/db

  database:
    container_name: immich_postgres
    image: postgres:14-bullseye
    user: 1026:100
    command: postgres -c unix_socket_directories='/var/run/postgresql/,/sockets/'
    env_file:
      - .env
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
      PG_DATA: /var/lib/postgresql/data
      PGPORT: ${DB_PORT}
    volumes:
      - $DOCKERDIR/immich/pgdata:/var/lib/postgresql/data
      - sockets:/sockets
    restart: always
Originally created by @JVT038 on GitHub (Jan 19, 2023). **Describe the bug** I have supplied the environment variables to use Redis with unix socket instead of TCP. The `.env` looks like this: ```markdown # REDIS_HOSTNAME=immich_redis # Optional Redis settings: # REDIS_PORT=6379 # REDIS_DBINDEX=0 REDIS_PASSWORD="a very long password" REDIS_SOCKET=/sockets/immich_redis.sock ``` The REDIS_PORT and REDIS_HOSTNAME are commented out, so Immich shouldn't try to connect with those values. However, it does. It shows this in the docker-compose logs: ``` immich-server_1 | Error: connect ECONNREFUSED 192.168.64.3:6379 immich-server_1 | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16) immich-server_1 | Emitted 'error' event on Commander instance at: immich-server_1 | at RedisSocket.<anonymous> (/usr/src/app/node_modules/@redis/client/dist/lib/client/index.js:360:14) immich-server_1 | at RedisSocket.emit (node:events:527:28) immich-server_1 | at RedisSocket._RedisSocket_connect (/usr/src/app/node_modules/@redis/client/dist/lib/client/socket.js:153:18) immich-server_1 | at processTicksAndRejections (node:internal/process/task_queues:96:5) immich-server_1 | at async Commander.connect (/usr/src/app/node_modules/@redis/client/dist/lib/client/index.js:173:9) immich-server_1 | at async Promise.all (index 0) immich-server_1 | at async RedisIoAdapter.connectToRedis (/usr/src/app/dist/apps/immich/apps/immich/src/middlewares/redis-io.adapter.middleware.js:18:9) immich-server_1 | at async bootstrap (/usr/src/app/dist/apps/immich/apps/immich/src/main.js:31:5) { immich-server_1 | errno: -111, immich-server_1 | code: 'ECONNREFUSED', immich-server_1 | syscall: 'connect', immich-server_1 | address: '192.168.64.3', immich-server_1 | port: 6379 immich-server_1 | } ``` Additionally, it somehow manages to connect to the right IP address. The internal IP of my Redis container is `192.168.64.3` and that's exactly what the server tries to connect to. I have set the port to 0 in my redis configuration, so that it would block all TCP requests, but that gives this error. Immich has never had a problem with my unix socket configuration up until the latest version `v1.42.0`, so I'm suspecting that that update has done something that broke my unix socket configuration. I managed to temporarily resolve this by connecting over TCP instead of Unix, but I would like to be able to use an Unix socket, because the Unix sockets are faster than TCP. **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.* - [x] I have read thoroughly the README setup and installation instructions. - [ ] I have included my `docker-compose` file. - [x] I have included my redacted `.env` file. - [x] I have included information on my machine, and environment. **To Reproduce** Steps to reproduce the behavior: 1. Set up Immich with Redis Unix socket connection 2. Start the containers 3. See error **Expected behavior** I expected Immich to connect with my Redis container over unix instead of TCP. **System** - Phone OS [iOS, Android]: `Android 12` - Server Version: `v1.42.0` - Mobile App Version: `v1.41.0` **Additional context** I use a Traefik proxy to connect and don't use the Immich NGINX proxy container. In case that matters, here is my `docker-compose.yml` ```yml version: "3.8" networks: traefik_proxy: external: name: traefik_proxy services: immich-server: image: altran1502/immich-server:release entrypoint: ["/bin/sh", "./start-server.sh"] networks: - traefik_proxy - default volumes: - ${UPLOAD_LOCATION}:/usr/src/app/upload - sockets:/sockets env_file: - .env environment: - NODE_ENV=production depends_on: - redis - database restart: always labels: traefik.enable: "true" traefik.docker.network: traefik_proxy traefik.http.services.immich-api-svc.loadbalancer.server.port: "3001" traefik.http.routers.immich-api-rtr.rule: "Host(`immich.$DOMAINNAME`) && Pathprefix(`/api`)" traefik.http.routers.immich-api-rtr.priority: 20 traefik.http.middlewares.immich-api-strip.stripprefix.prefixes: "/api" traefik.http.routers.immich-api-rtr.middlewares: immich-api-strip,chain-basic@file traefik.http.routers.immich-api-rtr.service: immich-api-svc traefik.http.routers.immich-api-rtr.tls: true traefik.http.routers.immich-api-rtr.tls.certresolver: dns-cloudflare traefik.http.routers.immich-api-rtr.entrypoints: https immich-microservices: image: altran1502/immich-server:release entrypoint: ["/bin/sh", "./start-microservices.sh"] networks: - default volumes: - ${UPLOAD_LOCATION}:/usr/src/app/upload - sockets:/sockets env_file: - .env environment: - NODE_ENV=production depends_on: - redis - database restart: always immich-machine-learning: build: context: $DOCKERDIR/immich/immich-ml dockerfile: Dockerfile entrypoint: ["/bin/sh", "./entrypoint.sh"] networks: - default volumes: - ${UPLOAD_LOCATION}:/usr/src/app/upload env_file: - .env environment: - NODE_ENV=production depends_on: - database restart: always immich-web: image: altran1502/immich-web:release entrypoint: ["/bin/sh", "./entrypoint.sh"] networks: - default - traefik_proxy env_file: - .env restart: always labels: traefik.enable: "true" traefik.docker.network: traefik_proxy traefik.http.services.immich-svc.loadbalancer.server.port: "3000" traefik.http.routers.immich-rtr.rule: "Host(`immich.$DOMAINNAME`)" traefik.http.routers.immich-rtr.priority: 10 traefik.http.routers.immich-rtr.service: immich-svc traefik.http.routers.immich-rtr.middlewares: chain-basic@file traefik.http.routers.immich-rtr.tls: true traefik.http.routers.immich-rtr.tls.certresolver: dns-cloudflare traefik.http.routers.immich-rtr.entrypoints: https redis: container_name: immich_redis image: redis:6.2 restart: always networks: - default command: redis-server /etc/redis.conf volumes: - sockets:/sockets - $DOCKERDIR/immich/redis.conf:/etc/redis.conf - /etc/TZ:/etc/timezone:ro - $DOCKERDIR/immich/redisdb:/db database: container_name: immich_postgres image: postgres:14-bullseye user: 1026:100 command: postgres -c unix_socket_directories='/var/run/postgresql/,/sockets/' env_file: - .env environment: POSTGRES_PASSWORD: ${DB_PASSWORD} POSTGRES_USER: ${DB_USERNAME} POSTGRES_DB: ${DB_DATABASE_NAME} PG_DATA: /var/lib/postgresql/data PGPORT: ${DB_PORT} volumes: - $DOCKERDIR/immich/pgdata:/var/lib/postgresql/data - sockets:/sockets restart: always ```
Author
Owner

@bo0tzz commented on GitHub (Jan 19, 2023):

It looks like the socket support got (accidentally @alextran1502?) commented out when updating nestjs. Since there are defaults set for the host and port, those got picked up and happened to be correct.

A few notes for when this is picked up to fix:

  1. We should probably avoid applying the host/port defaults if a socket is configured (even though it hasn't seemed to be a problem so far)
  2. It seems there are two places where redis gets configured: bull-queue.config.ts and redis-io.adapter.middleware.ts. I would expect we can probably deduplicate this.
@bo0tzz commented on GitHub (Jan 19, 2023): It looks like the socket support got (accidentally @alextran1502?) commented out [when updating nestjs](https://github.com/immich-app/immich/pull/1312/files). Since [there are defaults set](https://github.com/immich-app/immich/blob/main/server/apps/immich/src/middlewares/redis-io.adapter.middleware.ts#L6-L7) for the host and port, those got picked up and happened to be correct. A few notes for when this is picked up to fix: 1. We should probably avoid applying the host/port defaults if a socket is configured (even though it hasn't seemed to be a problem so far) 2. It seems there are two places where redis gets configured: [bull-queue.config.ts](https://github.com/immich-app/immich/blob/main/server/libs/common/src/config/bull-queue.config.ts) and [redis-io.adapter.middleware.ts](https://github.com/immich-app/immich/blob/main/server/apps/immich/src/middlewares/redis-io.adapter.middleware.ts). I would expect we can probably deduplicate this.
Author
Owner

@alextran1502 commented on GitHub (Feb 2, 2023):

Reimplemented in https://github.com/immich-app/immich/pull/1494

@alextran1502 commented on GitHub (Feb 2, 2023): Reimplemented in https://github.com/immich-app/immich/pull/1494
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#599