From d43f0200a6805d57dcef2f3ab3595a729f01008e Mon Sep 17 00:00:00 2001 From: Maycon Santos Date: Tue, 6 Dec 2022 15:37:30 +0100 Subject: [PATCH] Handle peer deletion and state update (#611) If peer is deleted in the console, we set its state as needs login On Down command we clean any previous state errors this prevents need for daemon restart Removed state error wrapping when engine exits, log is enough --- client/internal/connect.go | 3 +++ client/server/server.go | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/client/internal/connect.go b/client/internal/connect.go index 2c55c2b28..c13df0888 100644 --- a/client/internal/connect.go +++ b/client/internal/connect.go @@ -177,6 +177,9 @@ func RunClient(ctx context.Context, config *Config, statusRecorder *nbStatus.Sta err = backoff.Retry(operation, backOff) if err != nil { log.Debugf("exiting client retry loop due to unrecoverable error: %s", err) + if s, ok := gstatus.FromError(err); ok && (s.Code() == codes.PermissionDenied) { + state.Set(StatusNeedsLogin) + } return err } return nil diff --git a/client/server/server.go b/client/server/server.go index 2beeca609..a5fb3423b 100644 --- a/client/server/server.go +++ b/client/server/server.go @@ -335,7 +335,7 @@ func (s *Server) WaitSSOLogin(callerCtx context.Context, msg *proto.WaitSSOLogin } // Up starts engine work in the daemon. -func (s *Server) Up(callerCtx context.Context, msg *proto.UpRequest) (*proto.UpResponse, error) { +func (s *Server) Up(callerCtx context.Context, _ *proto.UpRequest) (*proto.UpResponse, error) { s.mutex.Lock() defer s.mutex.Unlock() @@ -375,7 +375,7 @@ func (s *Server) Up(callerCtx context.Context, msg *proto.UpRequest) (*proto.UpR go func() { if err := internal.RunClient(ctx, s.config, s.statusRecorder); err != nil { - log.Errorf("run client connection: %v", state.Wrap(err)) + log.Errorf("run client connection: %v", err) return } }() @@ -384,7 +384,7 @@ func (s *Server) Up(callerCtx context.Context, msg *proto.UpRequest) (*proto.UpR } // Down engine work in the daemon. -func (s *Server) Down(ctx context.Context, msg *proto.DownRequest) (*proto.DownResponse, error) { +func (s *Server) Down(_ context.Context, _ *proto.DownRequest) (*proto.DownResponse, error) { s.mutex.Lock() defer s.mutex.Unlock() @@ -392,6 +392,8 @@ func (s *Server) Down(ctx context.Context, msg *proto.DownRequest) (*proto.DownR return nil, fmt.Errorf("service is not up") } s.actCancel() + state := internal.CtxGetState(s.rootCtx) + state.Set(internal.StatusIdle) return &proto.DownResponse{}, nil } @@ -425,7 +427,7 @@ func (s *Server) Status( } // GetConfig of the daemon. -func (s *Server) GetConfig(ctx context.Context, msg *proto.GetConfigRequest) (*proto.GetConfigResponse, error) { +func (s *Server) GetConfig(_ context.Context, _ *proto.GetConfigRequest) (*proto.GetConfigResponse, error) { s.mutex.Lock() defer s.mutex.Unlock()