Error: invalid host in logs

Description

I launched Rocket Chat in Docker Compose according to the instructions Deploy with Docker & Docker Compose. It works well, but there are two problems:

  1. The web app and desktop sometimes do not open random chats. You have to close/open the browser or close/open the desktop app. After that, it works fine.
  2. The “Remind me about this” function stopped working.

To fix these problems, I went to the logs of the Rocket Chat container. Everything is fine in the logs, but sometimes this error appears:

"level":50,
"time":"2024-08-15T08:14:35.245Z",
"pid":1,
"hostname":"f4b696898f15",
"name":"OEmbed",
"msg":"Error fetching url content",
"err":{
    "type":"Error", 
    "message":"invalid host",
    "stack":
    "Error: invalid host  
        at app/oembed/server/server.ts:79:9
        at /app/bundle/programs/server/npm/node_modules/meteor/promise/node_modules/meteor-promise/fiber_pool.js:43:40 
        => awaited here:    
        at Function.Promise.await (/app/bundle/programs/server/npm/node_modules/meteor/promise/node_modules/meteor-promise/promise_server.js:56:12)    
        at app/oembed/server/server.ts:187:10  
        at /app/bundle/programs/server/npm/node_modules/meteor/promise/node_modules/meteor-promise/fiber_pool.js:43:40 
    "
}

Mongo logs look fine. Nginx logs look fine.
I can’t figure out what causes this error. Is it possible to configure Rocket Chat to give more information in the logs? What other ways are there to find the cause of my problems?

Server Setup Information

  • Version of Rocket.Chat Server: registry.rocket.chat/rocketchat/rocket.chat:6.10.2
  • Operating System: Debian 11
  • Deployment Method: docker
  • Number of Running Instances: 1
  • DB Replicaset Oplog: I don’t know
  • NodeJS Version: 14.21.3
  • MongoDB Version: bitnami/mongodb:6.0.5
  • Proxy: nginx
  • Firewalls involved: no

Any additional Information

rocketchat@f4b696898f15:/app/bundle$ env
HOSTNAME=f4b696898f15
YARN_VERSION=1.22.19
PWD=/app/bundle
PORT=3000
NODE_ENV=production
Accounts_AvatarStorePath=/app/uploads
DEPLOY_METHOD=docker
HOME=/tmp
DEPLOY_PLATFORM=
DENO_DIR=/usr/share/deno
TERM=xterm
SHLVL=1
ROOT_URL=https://rc.mydomain.com
MONGO_OPLOG_URL=mongodb://mongodb:27017/local?replicaSet=rs0&directConnection=true
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
MONGO_URL=mongodb://mongodb:27017/rocketchat?replicaSet=rs0&directConnection=true
NODE_VERSION=14.21.3
_=/usr/bin/env

So you are running this with https/ssl via a reverse proxy to your install as per the docs?

Have you set up a file store instead of GridFS?

We might need to see your compose file and and nginx config. Just modify any sensitive information.

Have you checked your websockets are OK?

See here for how to test that:

Thanks for the quick reply!
I went to read the docs on ssl setup. I will also find out the answer about GridFS. Then I will come back with the information.

Websocket is fine now. When problems appear, I will definitely check websocket again.

Now I’ll attach docker-compose, variables file and nginx.conf.
docker-compose.yaml:

volumes:
  mongodb_data: { driver: local }
  rc_cache: { driver: local }

services:
  rocketchat:
    image: registry.rocket.chat/rocketchat/rocket.chat:${RELEASE:-latest}
    restart: on-failure
    labels:
      traefik.enable: "false"
      traefik.http.routers.rocketchat.rule: Host(`${DOMAIN}`)
      traefik.http.routers.rocketchat.tls: "true"
      traefik.http.routers.rocketchat.entrypoints: https
      traefik.http.routers.rocketchat.tls.certresolver: le
    volumes:
      - rc_cache:/var/cache/rocketchat
    environment:
      MONGO_URL: "${MONGO_URL:-\
        mongodb://${MONGODB_ADVERTISED_HOSTNAME:-mongodb}:${MONGODB_INITIAL_PRIMARY_PORT_NUMBER:-27017}/\
        ${MONGODB_DATABASE:-rocketchat}?replicaSet=${MONGODB_REPLICA_SET_NAME:-rs0}}&directConnection=true"
      MONGO_OPLOG_URL: "${MONGO_OPLOG_URL:\
        -mongodb://${MONGODB_ADVERTISED_HOSTNAME:-mongodb}:${MONGODB_INITIAL_PRIMARY_PORT_NUMBER:-27017}/\
        local?replicaSet=${MONGODB_REPLICA_SET_NAME:-rs0}}&directConnection=true"
      ROOT_URL: ${ROOT_URL:-http://localhost:${HOST_PORT:-3001}}
      PORT: ${PORT:-3000}
      DEPLOY_METHOD: docker
      DEPLOY_PLATFORM: ${DEPLOY_PLATFORM}
    depends_on:
      - mongodb
    expose:
      - ${PORT:-3000}
    ports:
      - "${BIND_IP:-0.0.0.0}:${HOST_PORT:-3001}:${PORT:-3000}"

  mongodb:
    image: docker.io/bitnami/mongodb:${MONGODB_VERSION:-6.0.5}
    restart: on-failure
    volumes:
      - mongodb_data:/bitnami/mongodb
    environment:
      MONGODB_REPLICA_SET_MODE: primary
      MONGODB_REPLICA_SET_NAME: ${MONGODB_REPLICA_SET_NAME:-rs0}
      MONGODB_PORT_NUMBER: ${MONGODB_PORT_NUMBER:-27017}
      MONGODB_INITIAL_PRIMARY_HOST: ${MONGODB_INITIAL_PRIMARY_HOST:-mongodb}
      MONGODB_INITIAL_PRIMARY_PORT_NUMBER: ${MONGODB_INITIAL_PRIMARY_PORT_NUMBER:-27017}
      MONGODB_ADVERTISED_HOSTNAME: ${MONGODB_ADVERTISED_HOSTNAME:-mongodb}
      MONGODB_ENABLE_JOURNAL: ${MONGODB_ENABLE_JOURNAL:-true}
      ALLOW_EMPTY_PASSWORD: ${ALLOW_EMPTY_PASSWORD:-yes}

.env:

### Rocket.Chat configuration

# Rocket.Chat version
# see:- https://github.com/RocketChat/Rocket.Chat/releases
RELEASE=6.10.2
# MongoDB endpoint (include ?replicaSet= parameter)
#MONGO_URL=
# MongoDB endpoint to the local database
#MONGO_OPLOG_URL=
# IP to bind the process to
BIND_IP=127.0.0.1
# URL used to access your Rocket.Chat instance
ROOT_URL=https://rc.mydomain.com
# Port Rocket.Chat runs on (in-container)
#PORT=
# Port on the host to bind to
HOST_PORT=3001

### MongoDB configuration
# MongoDB version/image tag
MONGODB_RELEASE=6.0.5
# See:- https://hub.docker.com/r/bitnami/mongodb

### Traefik config (if enabled)
# Traefik version/image tag
#TRAEFIK_RELEASE=
# Domain for https (change ROOT_URL & BIND_IP accordingly)
#DOMAIN=
# Email for certificate notifications

nginx.conf:

server {
  server_name rc.mydomain.com;
  access_log  /var/log/nginx/rc_access.log;
  error_log   /var/log/nginx/rc_error.log;

    location / {
      proxy_pass http://127.0.0.1:3001;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto https;
      proxy_set_header X-Nginx-Proxy true;
      proxy_redirect off;
    } 


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/rc.mydomain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/rc.mydomain.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}server {
    if ($host = rc.mydomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


  server_name rc.mydomain.com;


    listen 80;
    return 404; # managed by Certbot


}

Looks OK.

Any reason not to run it on 3001 ?

I don’t know the reasons. I inherited this server.

Ah OK - you made it sound like you had started it yourself.

OK - normally it would run on 3000.

I wonder if the server URL is incorrect in the DB.

You can see your error here:

And I was searching about and saw this:

HOSTNAME=f4b696898f15

I suspect that should be a properly resolvable hostname eg:

f4b696898f15.someresovabledomain.com

These often get messed up if people run a test server and then move it. Possibly some of the URLs for uploaded files are wrong as well.

Check the store settings here:

db.getCollection(“rocketchat_uploads”).find({})

Have a look for the host - something like this (I am useless with Mongo)

db.getCollection("rocketchat_settings").find({value: {$regex: 'f4b6', $options: 'i'}});

Thank you! I need to figure this out. I don’t understand how I can use this.
HOSTNAME=f4b696898f15 is the container ID. This variable is set by Docker when the container starts without my participation.

OK - brain not engaged. Long nights :frowning:

The Internal docker hostname is not resolvable from elsewhere (unless you use host mode). So not that.

I had a chat with a dev.

This error relates to malformed URLs for link previews.

that code is related to rendering the link previews I believe; for example once you share an YT link and how the RC tries to show a preview.

The OP can see which URL is causing the issue, it will be just above the error log they see starting with something along the Fetching url content...

You need to go and see if you can find one and see what it is.