Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't run the cache-server locally (Redis database connection error) #342

Open
syedmuhammaddanish opened this issue Feb 28, 2022 · 19 comments

Comments

@syedmuhammaddanish
Copy link

Hi, I am trying to run the iam-cache-server locally (without docker), and everything runs smoothly until I get the error "Unable to connect to the database. Retrying (1), Connection terminated due to connection timeout".

Also this error is shown in the end.

errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'redis'

Can you please help in out in resolving the issue. Thank you.
issue1

@jrhender
Copy link
Collaborator

jrhender commented Mar 1, 2022

Hi @syedmuhammaddanish , I believe that you will need to run docker to have the redis, postgres and nats dependencies available. You can do this using the docker-compose.dev.yml file (though note #343) .
Or you can not run only the service dependencies in docker and run the app separately if you prefer. We can help you with that config if you want to do this.

@syedmuhammaddanish
Copy link
Author

Hi, If you could provide the configurations, that would be great. Thanks for the prompt response 👍

@jrhender
Copy link
Collaborator

jrhender commented Mar 2, 2022

Sure, here is an example docker-compose file that I think should work (possibly with some tweaking)

I've just commented out the app (so I run that directly using node) and then communicate with the services exposed via docker.

Let me know if this works for you!


services:
  # app:
  #   container_name: app
  #   build:
  #     context: .
  #     dockerfile: ./docker/dev/Dockerfile
  #   volumes:
  #     - .:/app
  #     - /app/node_modules
  #   ports:
  #     - ${NESTJS_PORT}:${NESTJS_PORT}
  #     - 9229:9229
  #   command: npm run start:dev
  #   env_file:
  #     - .env
  #   networks:
  #     - main
  #   depends_on:
  #     - nats
  #     - postgres
  postgres:
    image: postgres:12-alpine
    environment:
      POSTGRES_PASSWORD: password
      POSTGRES_USERNAME: postgres
      POSTGRES_DB: dev-test
    networks:
      - main
    ports:
      - 5432:5432
  nats:
    container_name: nats
    image: synadia/nats-server:nightly
    volumes:
      - ./config/:/etc/nats
    command: '-c /etc/nats/nats.conf'
    networks:
      - main
    ports:
      - '4222:4222'
      - '8222:8222'
      - '9222:9222'
  redis:
    container_name: redis
    image: redis:${REDIS_VERSION}
    command: redis-server --requirepass ${REDIS_PASSWORD}
    volumes:
      - $PWD/redis-data:/var/lib/redis
    ports:
      - '6379:6379'
    environment:
      - REDIS_REPLICATION_MODE=master
    networks:
      - main
networks:
  main:

@syedmuhammaddanish
Copy link
Author

Hi @jrhender ,

Thank you for providing the configurations. I can now run the service dependencies in the docker container. However, when I run the app using npm run start:dev, I get the same redis error. I tried a lot to debug by searching online but I don't know where exactly the problem is. The thing I am sure is the app cannot communicate with the Docker container. Here is the error.

issuedoc1

Moreover, instead of running app and service dependencies separately, I tried to run the combined docker-compose file (app and service dependencies in docker) and during docker:build, I got these weird errors. Do you have any idea about it. At step 7, it fails.

issuedoc3

@jrhender
Copy link
Collaborator

jrhender commented Mar 7, 2022

I suspect that you need update your .env file. For instance, I think REDIS_HOST should be localhost.

REDIS_PORT=6379
REDIS_HOST=localhost

Does this help you out?

@syedmuhammaddanish
Copy link
Author

syedmuhammaddanish commented Mar 12, 2022

Hi,

Thank you so much. It worked.

Here are the .env and docker-compose file if someone wants to run the services dependencies in docker compose and start application in node.

.env

# NESTJS CONFIG
NESTJS_PORT=5008

# DB CONFIG
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=password
DB_NAME=dev-test

# NATS.IO CONFIG
NATS_VERSION=2.1.8
NATS_CLIENTS_URL=nats://localhost:4222
NATS_ENVIRONMENT_NAME=

# ENS
CHAIN_ID=73799
CHAIN_NAME=volta
ENS_URL=https://volta-rpc-vkn5r5zx4ke71f9hcu0c.energyweb.org/
PUBLIC_RESOLVER_ADDRESS=0x0a97e07c4Df22e2e31872F20C5BE191D5EFc4680
ENS_REGISTRY_ADDRESS=0xd7CeF70Ba7efc2035256d828d5287e2D285CD1ac
DID_REGISTRY_ADDRESS=0xc15d5a57a8eb0e1dcbe5d88b8f9a82017e5cc4af
DOMAIN_NOTIFIER_ADDRESS=0xeea658026d6CDede4380D3aD030beAC911758A93
RESOLVER_V1_ADDRESS=0xf5EA22c1F799d425356c2aab2004200Ab4490D2b
RESOLVER_V2_ADDRESS=0xcf72f16Ab886776232bea2fcf3689761a0b74EfE
STAKING_POOL_FACTORY_ADDRESS=0x4b2A127680320eD980beAa7aD9b2447B96BC32fC

# ASSETS
ASSETS_MANAGER_ADDRESS=0x84d0c7284A869213CB047595d34d6044d9a7E14A
ASSETS_SYNC_INTERVAL_IN_HOURS=10
ASSETS_SYNC_HISTORY_INTERVAL_IN_HOURS=21
ASSETS_SYNC_ENABLED=true

# REDIS
REDIS_VERSION=6.0.8
REDIS_PASSWORD="password"
REDIS_PORT=6379
REDIS_HOST=localhost

# IPFS
IPFS_URL=https://ipfs.infura.io:5001/api/v0/

# INTERVALS
DIDDOC_SYNC_INTERVAL_IN_HOURS=12
DID_SYNC_ENABLED=true
DID_SYNC_MODE_FULL=true
ENS_SYNC_INTERVAL_IN_HOURS=11
ENS_SYNC_ENABLED=true

# AWS ECR
DOCKER_REGISTRY=
DOCKER_REPOSITORY=
DOCKER_TAG=

# AUTH
ENABLE_AUTH=true
JWT_PRIVATE_KEY=private.pem
JWT_PUBLIC_KEY=public.pem
STRATEGY_CACHE_SERVER=http://localhost:${NESTJS_PORT}/v1
STRATEGY_PRIVATE_KEY=
STRATEGY_NUM_BLOCKS_BACK=10
JWT_ACCESS_TOKEN_EXPIRES_IN=15m
JWT_REFRESH_TOKEN_EXPIRES_IN=1h
JWT_ACCESS_TOKEN_NAME=token
JWT_REFRESH_TOKEN_NAME=refreshToken

# DID UNIVERSAL RESOLVER
UNIVERSAL_RESOLVER_URL=https://dev.uniresolver.io/1.0/identifiers/

# SENTRY CONFIG
SENTRY_DNS=
SENTRY_ENV=
SENTRY_RELEASE=

# LOGS CONFIG
LOGS_DIRECTORY=

and docker-compose.yml file

version: '3.4'

services:
  # app:
  #   container_name: app
  #   build:
  #     context: .
  #     dockerfile: ./docker/dev/Dockerfile
  #   volumes:
  #     - .:/app
  #     - /app/node_modules
  #   ports:
  #     - ${NESTJS_PORT}:${NESTJS_PORT}
  #     - 9229:9229
  #   command: npm run start:dev
  #   env_file:
  #     - .env
  #   networks:
  #     - main
  #   depends_on:
  #     - nats
  #     - postgres
  postgres:
    image: postgres:12-alpine
    environment:
      POSTGRES_PASSWORD: password
      POSTGRES_USERNAME: postgres
      POSTGRES_DB: dev-test
    networks:
      - main
    ports:
      - 5432:5432
  nats:
    container_name: nats
    image: synadia/nats-server:nightly
    volumes:
      - ./config/:/etc/nats
    command: '-c /etc/nats/nats.conf'
    networks:
      - main
    ports:
      - '4222:4222'
      - '8222:8222'
      - '9222:9222'
  redis:
    container_name: redis
    image: redis:6.0.8
    command: redis-server --requirepass "password"
    volumes:
      - $PWD/redis-data:/var/lib/redis
    ports:
      - '6379:6379'
    environment:
      - REDIS_REPLICATION_MODE=master
    networks:
      - main
networks:
  main:

volumes:
  dgraph:

@syedmuhammaddanish
Copy link
Author

syedmuhammaddanish commented Mar 12, 2022

However, I think there is still some configuration problems as I am getting error with port 80 now.

Can you please check it as I think it is the configuration problem I guess


DID login strategy was not able to login to cache server due to {
    "error": {
        "message": "connect ECONNREFUSED IP_ADDRESS:80",
        "name": "Error",
        "stack": "Error: connect ECONNREFUSED IP_ADDRESS:80\n    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:DIGITS:16)",
        "config": {
            "transitional": {
                "silentJSONParsing": true,
                "forcedJSONParsing": true,
                "clarifyTimeoutError": false
            },
            "transformRequest": [
                null
            ],
            "transformResponse": [
                null
            ],
            "timeout": 0,
            "xsrfCookieName": "XSRF-TOKEN",
            "xsrfHeaderName": "X-XSRF-TOKEN",
            "maxContentLength": -1,
            "maxBodyLength": -1,
            "headers": {
                "Accept": "application/json, text/plain, */*",
                "Content-Type": "application/json",
                "User-Agent": "axios/0.26.0",
                "Content-Length": 373
            },
            "baseURL": URL
            "method": "post",
            "url": "/login",
            "data": "{\"identityToken\":\"eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkaWQ6ZXRocjp2b2x0YToweDMzY0NEN0IwMDc0OWY5YjM1RkYwNWNFMTY0NTQyZTFiNDRBMDU5NEUiLCJjbGFpbURhdGEiOnsiYmxvY2tOdW1iZXIiOjE2NDI5NDk3fX0.MHhlMjQ3Y2IxZTkzYWUxMWFhOWQ4YjU0Njk2YmUzODZiYTE3NmY2YTY4YmM0NDY4ZWEyOWRiMTU2MDc4NWNiNmI3NGVlMmY0MWMyOWNmNDcxZGEwNWNmYjk3MmIyOGUzMDYxNzQ4OTUxNWUzZjQ0NWNiNWRmMWYzNzI0ZDAzNGMzMDFj\"}"
        },
        "code": "ECONNREFUSED",
        "status": null
    }
}

@jrhender
Copy link
Collaborator

Hi @syedmuhammaddanish , sorry for the delay, I will take a look tmrw

@jrhender
Copy link
Collaborator

@syedmuhammaddanish I'm a bit stumped. I think that this error is because our authentication component embedded into the server is misconfigured. The relevant line in the .env file is STRATEGY_CACHE_SERVER=http://localhost:${NESTJS_PORT}/v1. But you had NESTJS_PORT=5008, not =80, so I don't know where the 80 is coming from. Do you know where the 80 might be coming from? Is it in your config anywhere?

@syedmuhammaddanish
Copy link
Author

syedmuhammaddanish commented Mar 20, 2022

Hi,

I have not put 80 anywhere in my configurations and I have pasted configuration above in this thread.

I am also confused what is happening. Everything goes fine until it sends the authentication request to localhost:80, instead of localhost/${NESTJS_PORT}/v1.

I think its not a good idea to run app and service dependencies individually.

I am trying to run everything from docker by following the installation guidelines but I am still receiving errors.

Can you kindly try to deploy the dev version of docker-compose yourself and see if it works fine. Because i tried everything. Even I tried ubuntu 16, 18 and 20 but no success. :(

@jrhender
Copy link
Collaborator

@syedmuhammaddanish Yes, of course, we will try the dev compose ourselves and see if it works. Apologies that it has been so difficult for you to run the project

@syedmuhammaddanish
Copy link
Author

Thank you for your support. I am looking forward.

@jrhender
Copy link
Collaborator

@syedmuhammaddanish
Copy link
Author

Thank you @jrhender .

@jrhender
Copy link
Collaborator

Hi @syedmuhammaddanish , #367 is merged. Could you try again when you have time please?

@jrhender
Copy link
Collaborator

You would need to use the latest code from the develop branch

@syedmuhammaddanish
Copy link
Author

Hi,

I tried running the project. Yesterday, it worked fine and i could see a cache-server running on localhost:3000. However, unfortunately, I had to re-install the cache server again. But this time, I am constantly getting this error and I don't really know why. The dependencies error has been resolved already as i was facing before. Can you please have a look at this

[5:06:06 AM] Starting compilation in watch mode...
app         | 
app         | src/modules/sentry/sentry-tracing.service.ts:8:36 - error TS2345: Argument of type 'import("/app/node_modules/@sentry/types/dist/transaction").TransactionContext' is not assignable to parameter of type 'import("/app/node_modules/@sentry/node/node_modules/@sentry/types/dist/transaction").TransactionContext'.
app         |   Types of property 'metadata' are incompatible.
app         |     Type 'import("/app/node_modules/@sentry/types/dist/transaction").TransactionMetadata' is not assignable to type 'import("/app/node_modules/@sentry/node/node_modules/@sentry/types/dist/transaction").TransactionMetadata'.
app         | 
app         | 8     return Sentry.startTransaction(params);
app         |                                      ~~~~~~
app         | 
app         | src/modules/sentry/sentry.service.ts:81:9 - error TS2322: Type 'RewriteFrames' is not assignable to type 'Integration'.
app         |   Types of property 'setupOnce' are incompatible.
app         |     Type '(addGlobalEventProcessor: (callback: import("/app/node_modules/@sentry/types/dist/eventprocessor").EventProcessor) => void, getCurrentHub: () => import("/app/node_modules/@sentry/types/dist/hub").Hub) => void' is not assignable to type '(addGlobalEventProcessor: (callback: import("/app/node_modules/@sentry/node/node_modules/@sentry/types/dist/eventprocessor").EventProcessor) => void, getCurrentHub: () => import("/app/node_modules/@sentry/node/node_modules/@sentry/types/dist/hub").Hub) => void'.
app         |       Types of parameters 'addGlobalEventProcessor' and 'addGlobalEventProcessor' are incompatible.
app         |         Types of parameters 'callback' and 'callback' are incompatible.
app         |           Type 'import("/app/node_modules/@sentry/types/dist/eventprocessor").EventProcessor' is not assignable to type 'import("/app/node_modules/@sentry/node/node_modules/@sentry/types/dist/eventprocessor").EventProcessor'.
app         |             Type 'import("/app/node_modules/@sentry/types/dist/event").Event | PromiseLike<import("/app/node_modules/@sentry/types/dist/event").Event>' is not assignable to type 'import("/app/node_modules/@sentry/node/node_modules/@sentry/types/dist/event").Event | PromiseLike<import("/app/node_modules/@sentry/node/node_modules/@sentry/types/dist/event").Event>'.
app         |               Type 'Event' is not assignable to type 'Event | PromiseLike<Event>'.
app         |                 Type 'import("/app/node_modules/@sentry/types/dist/event").Event' is not assignable to type 'import("/app/node_modules/@sentry/node/node_modules/@sentry/types/dist/event").Event'.
app         |                   Types of property 'spans' are incompatible.
app         |                     Type 'import("/app/node_modules/@sentry/types/dist/span").Span[]' is not assignable to type 'import("/app/node_modules/@sentry/node/node_modules/@sentry/types/dist/span").Span[]'.
app         |                       Type 'import("/app/node_modules/@sentry/types/dist/span").Span' is not assignable to type 'import("/app/node_modules/@sentry/node/node_modules/@sentry/types/dist/span").Span'.
app         |                         The types of 'transaction.metadata.transactionSampling' are incompatible between these types.
app         |                           Type '{ rate?: number; method?: TransactionSamplingMethod; }' is not assignable to type '{ rate?: number; method: TransactionSamplingMethod; }'.
app         |                             Property 'method' is optional in type '{ rate?: number; method?: TransactionSamplingMethod; }' but required in type '{ rate?: number; method: TransactionSamplingMethod; }'.
app         | 
app         | 81         new RewriteFrames({
app         |            ~~~~~~~~~~~~~~~~~~~
app         | 82           root: global.__rootdir__,
app         |    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
app         | 83         }),
app         |    ~~~~~~~~~~
app         | 
app         | src/modules/sentry/sentry.service.ts:99:17 - error TS2344: Type 'import("/app/node_modules/@sentry/types/dist/client").Client<import("/app/node_modules/@sentry/types/dist/options").Options>' does not satisfy the constraint 'import("/app/node_modules/@sentry/node/node_modules/@sentry/types/dist/client").Client<import("/app/node_modules/@sentry/node/node_modules/@sentry/types/dist/options").Options>'.
app         |   The types of 'getOptions().defaultIntegrations' are incompatible between these types.
app         |     Type 'false | import("/app/node_modules/@sentry/types/dist/integration").Integration[]' is not assignable to type 'false | import("/app/node_modules/@sentry/node/node_modules/@sentry/types/dist/integration").Integration[]'.
app         |       Type 'Integration[]' is not assignable to type 'false | Integration[]'.
app         |         Type 'import("/app/node_modules/@sentry/types/dist/integration").Integration[]' is not assignable to type 'import("/app/node_modules/@sentry/node/node_modules/@sentry/types/dist/integration").Integration[]'.
app         |           Type 'import("/app/node_modules/@sentry/types/dist/integration").Integration' is not assignable to type 'import("/app/node_modules/@sentry/node/node_modules/@sentry/types/dist/integration").Integration'.
app         |             Types of property 'setupOnce' are incompatible.
app         |               Type '(addGlobalEventProcessor: (callback: import("/app/node_modules/@sentry/types/dist/eventprocessor").EventProcessor) => void, getCurrentHub: () => import("/app/node_modules/@sentry/types/dist/hub").Hub) => void' is not assignable to type '(addGlobalEventProcessor: (callback: import("/app/node_modules/@sentry/node/node_modules/@sentry/types/dist/eventprocessor").EventProcessor) => void, getCurrentHub: () => import("/app/node_modules/@sentry/node/node_modules/@sentry/types/dist/hub").Hub) => void'.
app         |                 Types of parameters 'addGlobalEventProcessor' and 'addGlobalEventProcessor' are incompatible.
app         |                   Types of parameters 'callback' and 'callback' are incompatible.
app         |                     Type 'import("/app/node_modules/@sentry/types/dist/eventprocessor").EventProcessor' is not assignable to type 'import("/app/node_modules/@sentry/node/node_modules/@sentry/types/dist/eventprocessor").EventProcessor'.
app         | 
app         | 99                 Client<Options>
app         |                    ~~~~~~~~~~~~~~~
app         | 
app         | [5:06:17 AM] Found 3 errors. Watching for file changes.
app         | 

@syedmuhammaddanish
Copy link
Author

Just for your information, I tried changing ubuntu versions too but no success

@syedmuhammaddanish
Copy link
Author

@jrhender Sorry my bad,

I just tried changing node version from 16 to 14.19.1 and it worked. Getting this output..

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants