go-zero's BFF cannot find the key of the RPC service that has already been stored in the ETCD database

70 Views Asked by At

I am developing a personal project using the Go language framework Go-Zero. On the Golang side, there are four services: BFF(API service), and three RPC services named postsRpc, gauthRpc, and usersRpc, BBF depends on three Rpc service, as follows:

  1. BFF api service config:
Name: app
Host: 0.0.0.0
Port: 8888

UserRpc:
  Etcd:
    Hosts:
    - 127.0.0.1:2379
    Key: users.rpc

GauthRpc:
  Etcd:
    Hosts:
    - 127.0.0.1:2379
    Key: gauth.rpc

PostsRpc:
  Etcd:
    Hosts:
    - 127.0.0.1:2379
    Key: posts.rpc
  1. Three Rpc service config:

authRpc

Name: gauth.rpc
ListenOn: 0.0.0.0:8080
Etcd:
  Hosts:
  - 127.0.0.1:2379
  Key: gauth.rpc

Posts Rpc

Name: posts.rpc
ListenOn: 0.0.0.0:8082
Etcd:
  Hosts:
  - 127.0.0.1:2379
  Key: posts.rpc

UsersRpc

Name: users.rpc
ListenOn: 0.0.0.0:8081
Etcd:
  Hosts:
  - 127.0.0.1:2379
  Key: users.rpc

And I run a docker-compose in local machine, the yaml file content like this:

version: '3.1'

services:
  globaldb:
    image: mysql:8.0
    restart: always
    command: '--default-authentication-plugin=mysql_native_password'
    healthcheck:
      test: ['CMD-SHELL', 'mysqladmin ping -h 127.0.0.1 --password="$$(cat /run/secrets/db-password)" --silent']
      interval: 3s
      retries: 5
    ports:
      - "23306:3306"
    volumes:
      - ./db/db-data:/var/lib/mysql
    environment:
      MYSQL_DATABASE: globalfun
      MYSQL_ROOT_PASSWORD: root
    networks:
      - globalnet
  globalrd:
    image: redis:latest
    restart: always
    ports:
      - "26379:6379"
    command: redis-server --save 20 1 --loglevel warning --requirepass globalroot
    volumes:
      - ./rd:/data
    networks:
      - globalnet
  globaletcd:
    image: bitnami/etcd:latest
    restart: always
    ports:
      - "2379:2379"
    environment:
      - ALLOW_NONE_AUTHENTICATION=yes
    networks:
      - globalnet
  globalmongo:
    image: mongo:7.0.3
    container_name: globalmongo
    ports:
      - 27017:27017
    environment:
      - MONGO_INITDB_DATABASE=globalfun
#      - MONGO_INITDB_ROOT_USERNAME=admin
#      - MONGO_INITDB_ROOT_PASSWORD=globalroot
      - MONGO_INITDB_ROOT_USERNAME=root
      - MONGO_INITDB_ROOT_PASSWORD=globalroot
    volumes:
      # seeding scripts
      - ./mongo-entrypoint:/docker-entrypoint-initdb.d
      # named volumes
      - ./mongodata/mongodb:/data/db
      - ./mongodata/mongoconfig:/data/configdb
    networks:
      - globalnet
networks:
  globalnet:
    driver: bridge

when I run up three RPC services, The ETCD has three keys as follow:

@35458f0c3201:/opt/bitnami/etcd$ etcdctl get "" --prefix
gauth.rpc/7587875305045080324
192.168.31.119:8080
posts.rpc/7587875305045080330
192.168.31.119:8082
users.rpc/7587875305045080327
192.168.31.119:8081

But When I run BFF main go file : app.go, got a panic:

API server listening at: 127.0.0.1:2913
2023/12/13 21:05:21 rpc dial: etcd://127.0.0.1:2379/users.rpc, error: context deadline exceeded, make sure rpc service "users.rpc" is already started

goroutine 1 [running]:
runtime/debug.Stack()
        C:/Program Files/Go/src/runtime/debug/stack.go:24 +0x6b
github.com/zeromicro/go-zero/core/logx.Must({0x34b0ac0, 0xc0005b8050})
        C:/Users/vipda/go/pkg/mod/github.com/zeromicro/[email protected]/core/logx/logs.go:225 +0x57
github.com/zeromicro/go-zero/zrpc.MustNewClient({{{0xc00049ab30, 0x1, 0x1}, {0xc0005b1620, 0x9}, 0x0, {0x0, 0x0}, {0x0, 0x0}, ...}, ...}, ...)
        C:/Users/vipda/go/pkg/mod/github.com/zeromicro/[email protected]/zrpc/client.go:45 +0x13d
globalfun/globalfun/app/api/internal/svc.NewServiceContext({{{{0xc0005b15bc, 0x3}, {{...}, {...}, {...}, {...}, {...}, {...}, 0x0, 0x0, ...}, ...}, ...}, ...})
        C:/Users/person/projects/realworld/globalfun-go/globalfun/app/api/internal/svc/servicecontext.go:29 +0x65
main.main()
        C:/Users/person/projects/realworld/globalfun-go/globalfun/app/api/app.go:26 +0x187
{"@timestamp":"2023-12-13T21:05:21.849+08:00","content":"rpc dial: etcd://127.0.0.1:2379/users.rpc, error: context deadline exceeded, make sure rpc service \"users.rpc\" is already started\n\ngoroutine 1 [running]:\nruntime/debug.Stack()\n\tC:/Program Files/Go/src/runtime/debug/stack.go:24 +0x6b\ngithub.com/zeromicro/go-zero/core/logx.Must({0x34b0ac0, 0xc0005b8050})\n\tC:/Users/vipda/go/pkg/mod/github.com/zeromicro/[email protected]/core/logx/logs.go:225 +0x57\ngithub.com/zeromicro/go-zero/zrpc.MustNewClient({{{0xc00049ab3
0, 0x1, 0x1}, {0xc0005b1620, 0x9}, 0x0, {0x0, 0x0}, {0x0, 0x0}, ...}, ...}, ...)\n\tC:/Users/vipda/go/pkg/mod/github.com/zeromicro/[email protected]/zrpc/client.go:45 +0x13d\nglo
balfun/globalfun/app/api/internal/svc.NewServiceContext({{{{0xc0005b15bc, 0x3}, {{...}, {...}, {...}, {...}, {...}, {...}, 0x0, 0x0, ...}, ...}, ...}, ...})\n\tC:/Users/person
/projects/realworld/globalfun-go/globalfun/app/api/internal/svc/servicecontext.go:29 +0x65\nmain.main()\n\tC:/Users/person/projects/realworld/globalfun-go/globalfun/app/api/app.go:26 +0x187\n","level":"fatal"}

Debugger finished with the exit code 0

But the users.rpc Key already in the etcd, Why BFF api service can not found the key?? This really makes me feel frustrated, If anyone can found the panic reason, Please give me some advices.

1

There are 1 best solutions below

0
On

I found the reason for BFF cannot found users.rpc Key, it's caused by my local machine proxy env http_proxy/https_proxy set the value 127.0.0.1:7890, and proxy ip diff from docker container ip, so when I delete the http_proxy/https_proxy path, It worked! And Thx for everyone.