dunstorm / pm2-go

A pm2 clone built with go
Other
33 stars 5 forks source link

getting a connection errro for a golang application #6

Open danchengash opened 9 months ago

danchengash commented 9 months ago

rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial tcp 127.0.0.1:50051: connect: connection refused"

dunstorm commented 9 months ago

Can you explain steps to reproduce?

andersling commented 1 month ago

Can you explain steps to reproduce? pm2-go kill

pm2-go restore

will produce this error

I modify the client add prcess function ,and everything goes well:

func (c Client) AddProcess(request pb.AddProcessRequest) int32 { ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() retry_count := 0 retry: conn, manager := c.Dial() defer conn.Close()

r, err := (*manager).AddProcess(ctx, request)
if err != nil {
    err_msg := err.Error()
    fmt.Println("\n \033[36m", time.Now().Format(time.DateTime),
        " \033[0m> \033[33m", "Client > AddProcess > error:\033[31m", err, "\n\033[0m")

    if strings.ContainsAny(err_msg, "connect: connection refused") {
        //rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial tcp 127.0.0.1:50055: connect: connection refused"
        cmd := exec.Command("pm2", "-d")

        out, err := cmd.CombinedOutput()
        if err != nil {
            fmt.Println("WiFiDevice_Get_WiFiStatus error:", err)

        } else {
            fmt.Println("\n \033[36m", time.Now().Format(time.DateTime),
                " \033[0m> \033[32m", ">> ", string(out), "\n\033[0m")
            retry_count++
            if retry_count < 3 {
                time.Sleep(time.Millisecond * 100)
                fmt.Println("\n \033[36m", time.Now().Format(time.DateTime),
                    " \033[0m> \033[32m", "retry > AddProcess > time:", retry_count, "\n\033[0m")

                goto retry
            }

        }

    }
    c.logger.Fatal().Msgf("AddProcess:%s", err_msg)
}
return r.GetId()

}

BTW, thanks for your great job! Sir