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

Unable to connect redis from VPS server but can connect from other #1952

Open
hieunm22 opened this issue Feb 3, 2025 · 0 comments
Open

Unable to connect redis from VPS server but can connect from other #1952

hieunm22 opened this issue Feb 3, 2025 · 0 comments

Comments

@hieunm22
Copy link

hieunm22 commented Feb 3, 2025

Hi everyone,
I have a VPS with public IP, installed docker to use other services such as redis, rabbit mq, ... as external services
here's my docker-compose file

version: '3'

services:
  api:
    build:
      context: .
      dockerfile: ./App.API/Dockerfile-API
    ports:
      - "3333:5000"
    restart: "unless-stopped"
    environment:
      DATABASE_CONNECTION_STRING: "Data Source=database;Initial Catalog=app;User ID=sa;Password=<database_password>;TrustServerCertificate=True"
      GOOGLE_APP_PASSWORD: <google_app_password>
    networks:
      - app-network
  # ........

  cache:
    container_name: cache
    image: redis:alpine
    ports:
      - "6379:6379"
    restart: "unless-stopped"
    networks:
      - app-network
  # docker run --name cache -ditp 6379:6379 --network app-network --restart unless-stopped redis:alpine

networks:
  app-network:
    driver: bridge

The api service is created by Dotnet as backend, needs to connect redis from same docker network (app-network)
But when I start the API, the api shows the logs

Unhandled exception. StackExchange.Redis.RedisConnectionException: The message timed out in the backlog attempting to send because no connection became available (5000ms) - Last Connection Exception: It was not possible to connect to the redis server(s). ConnectTimeout, command=GET, timeout: 5000, inst: 0, qu: 1, qs: 0, aw: False, bw: SpinningDown, rs: NotStarted, ws: Idle, in: 0, last-in: 0, cur-in: 0, sync-ops: 1, async-ops: 0, serverEndpoint: 103.186.65.94:6379, conn-sec: n/a, aoc: 0, mc: 1/1/0, mgr: 10 of 10 available, clientName: 676ed7d04882(SE.Redis-v2.7.27.49176), IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=0,Free=32767,Min=4,Max=32767), POOL: (Threads=5,QueuedItems=0,CompletedItems=133,Timers=13), v: 2.7.27.49176 (Please take a look at this article for some common client-side issues that can cause timeouts: https://stackexchange.github.io/StackExchange.Redis/Timeouts)
 ---> StackExchange.Redis.RedisConnectionException: It was not possible to connect to the redis server(s). ConnectTimeout
   --- End of inner exception stack trace ---
   at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor`1 processor, ServerEndPoint server, T defaultValue) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 2105
......

The connection string in backend api service is
cache:6379,password=,ssl=true,abortConnect=False

Looks like the api cannot connect to cache service althought they're in same network (app-network)

I tried to change connection string above to the VPS public IP address but it still doesn't work
<ip-address>:6379,password=,ssl=true,abortConnect=False

But when I tried to run the api locally, with connection string contains the IP address then it works fine.
I don't know how to fix this issue, and how do I need to correct this issue in VPS server (local environment works fine)
That's my issue. Thanks everyone for your attention

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

1 participant