matrix-org / synapse

Synapse: Matrix homeserver written in Python/Twisted.
https://matrix-org.github.io/synapse
Apache License 2.0
11.82k stars 2.13k forks source link

Docker error: local user with ID 991 does not exist #16285

Closed alirezaalavi87 closed 11 months ago

alirezaalavi87 commented 1 year ago

Hi. I couldn't resolve my issue by asking in the matrix server. I use docker compose to run the app:

# This compose file is compatible with Compose itself, it might need some
# adjustments to run properly with stack.

version: '3'

services:

  synapse:
    build:
        context: ../..
        dockerfile: docker/Dockerfile
    image: docker.io/matrixdotorg/synapse:latest
    # Since synapse does not retry to connect to the database, restart upon
    # failure
    restart: unless-stopped
    # See the readme for a full documentation of the environment settings
    # NOTE: You must edit homeserver.yaml to use postgres, it defaults to sqlite
    environment:
      - SYNAPSE_CONFIG_PATH=/data/homeserver.yaml
    volumes:
      # You may either store all the files in a local folder
      - ./files:/data
    depends_on:
      - db
    # In order to expose Synapse, remove one of the following, you might for
    # instance expose the TLS port directly:
    ports:
      - 8008:8008/tcp

  db:
    image: docker.io/postgres:12-alpine
    # Change that password, of course!
    environment:
      - POSTGRES_USER=synapse
      - POSTGRES_PASSWORD=123
      # ensure the database gets created correctly
      # https://matrix-org.github.io/synapse/latest/postgres.html#set-up-database
      - POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=C --lc-ctype=C
    volumes:
      # You may store the database tables in a local folder..
      - ./schemas:/var/lib/postgresql/data
      # .. or store them on some high performance storage for better results
      # - /path/to/ssd/storage:/var/lib/postgresql/data

And I get this error:

synapse-synapse-1  |  Error during initialisation:
synapse-synapse-1  |      Traceback (most recent call last):
synapse-synapse-1  |        File "/usr/local/lib/python3.11/site-packages/synapse/app/homeserver.py", line 353, in setup
synapse-synapse-1  |          hs.setup()
synapse-synapse-1  |        File "/usr/local/lib/python3.11/site-packages/synapse/server.py", line 340, in setup
synapse-synapse-1  |          self.datastores = Databases(self.DATASTORE_CLASS, self)
synapse-synapse-1  |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
synapse-synapse-1  |        File "/usr/local/lib/python3.11/site-packages/synapse/storage/databases/__init__.py", line 65, in __init__
synapse-synapse-1  |          with make_conn(database_config, engine, "startup") as db_conn:
synapse-synapse-1  |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
synapse-synapse-1  |        File "/usr/local/lib/python3.11/site-packages/synapse/storage/database.py", line 161, in make_conn
synapse-synapse-1  |          native_db_conn = engine.module.connect(**db_params)
synapse-synapse-1  |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
synapse-synapse-1  |        File "/usr/local/lib/python3.11/site-packages/psycopg2/__init__.py", line 122, in connect
synapse-synapse-1  |          conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
synapse-synapse-1  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
synapse-synapse-1  |      psycopg2.OperationalError: local user with ID 991 does not exist

I have found this related issue: https://github.com/matrix-org/synapse/issues/13190 but still don't understand what causes it and how to fix it.

clokep commented 1 year ago

Did you make any changes to your Dockerfile?

Does removing the following fix the issue?

    build:
        context: ../..
        dockerfile: docker/Dockerfile

Please use synapse admins for support requests.

alirezaalavi87 commented 1 year ago

No it doesn't. also I figured (with the help of friends in matrix group) that my docker is in rootless mode. but still pruning everything and running with sudo doesn't fix the issue.

I asked in the matrix chat and they tried to help, but issue didn't get fixed. and wouldn't having issues and their solutions in here be better since they're easily searchable?

reivilibre commented 1 year ago

have you specified a Postgres host and username in your database configuration? I can see this happening if psycopg2 is about to try to connect to the (hypothetical in this case) local Postgres server using a UNIX socket and is attempting to determine the local user's name.

alirezaalavi87 commented 11 months ago

@reivilibre yes, the configs are correct. I am no longer trying to run synapse, but I think adding this to the docker-compose.yml fixed the issue:

    environment:
      - UID=0

I will close this issue since I'm not trying to run a synapse server at the moment and am not 100% sure how I fixed the issue (or did I fix it at all) but anyone with the same issue can open it again