golang gRPC update image in docker swarm having to

2019-07-25 23:55发布

问题:

I have a docker swarm on three nodes plus an external mysql service (outside of the swarm). I am programming micro-services with an API Gateway in golang and gRPC. I have two problems.

The first problem is when I push an update a service with docker swarm update --image ... myservice I get the error on my API Gateway from each micro-service transport is closing for three requests to the gateway. (I am assuming each task needs to reconnect on each service?) How can I fix this? Each service has update-delay set to 30s and update-parallelism set to 1. Shouldn't the api gateway stay connected to each service if there are rolling updates?

The second problem is after an idol time (not sure how long) I am getting the same issue from above that the services are closing and I have to do three requests to the api gateway for it to work. Any help appreciated. I am running Ubuntu 16.04 with Docker version 17.12.0-ce, build c97c6d6 and am building go version go1.9.4 darwin/amd64

A service example:

  // listen on address
    lis, err := net.Listen(network, address)
    if err != nil {
        log.Fatalf("failed to listen: %v", err)
    }
    defer lis.Close()

    // create users server
    s := grpc.NewServer()
    pb.RegisterUsersServer(s, &server{})

    // register reflection service on gRPC server.
    reflection.Register(s)

    // message will run after serve if err == nil
    go func() {
        time.Sleep(time.Second)
        log.Printf("started users service on %s", address)
    }()
    if err := s.Serve(lis); err != nil {
        log.Fatalf("failed to serve: %v", err)
    }

My api gateway connection

// connect to users
usersConnection, err := grpc.Dial(usersAddress, grpc.WithInsecure())
if err != nil {
    log.Fatalf("did not connect: %v", err)
}
users = userspb.NewUsersClient(usersConnection)
log.Println("connected to users")