diff --git a/client/cmd/up.go b/client/cmd/up.go index e686625d6..860a0dc14 100644 --- a/client/cmd/up.go +++ b/client/cmd/up.go @@ -230,7 +230,7 @@ func runInDaemonMode(ctx context.Context, cmd *cobra.Command, pm *profilemanager client := proto.NewDaemonServiceClient(conn) - status, err := client.Status(ctx, &proto.StatusRequest{}) + status, err := client.Status(ctx, &proto.StatusRequest{WaitForConnectingShift: true}) if err != nil { return fmt.Errorf("unable to get daemon status: %v", err) } diff --git a/client/proto/daemon.pb.go b/client/proto/daemon.pb.go index c633afc83..0cf45ed06 100644 --- a/client/proto/daemon.pb.go +++ b/client/proto/daemon.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.36.6 -// protoc v5.29.3 +// protoc v3.21.9 // source: daemon.proto package proto @@ -791,11 +791,12 @@ func (*UpResponse) Descriptor() ([]byte, []int) { } type StatusRequest struct { - state protoimpl.MessageState `protogen:"open.v1"` - GetFullPeerStatus bool `protobuf:"varint,1,opt,name=getFullPeerStatus,proto3" json:"getFullPeerStatus,omitempty"` - ShouldRunProbes bool `protobuf:"varint,2,opt,name=shouldRunProbes,proto3" json:"shouldRunProbes,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + GetFullPeerStatus bool `protobuf:"varint,1,opt,name=getFullPeerStatus,proto3" json:"getFullPeerStatus,omitempty"` + ShouldRunProbes bool `protobuf:"varint,2,opt,name=shouldRunProbes,proto3" json:"shouldRunProbes,omitempty"` + WaitForConnectingShift bool `protobuf:"varint,3,opt,name=waitForConnectingShift,proto3" json:"waitForConnectingShift,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *StatusRequest) Reset() { @@ -842,6 +843,13 @@ func (x *StatusRequest) GetShouldRunProbes() bool { return false } +func (x *StatusRequest) GetWaitForConnectingShift() bool { + if x != nil { + return x.WaitForConnectingShift + } + return false +} + type StatusResponse struct { state protoimpl.MessageState `protogen:"open.v1"` // status of the server. @@ -4673,10 +4681,11 @@ const file_daemon_proto_rawDesc = "" + "\f_profileNameB\v\n" + "\t_username\"\f\n" + "\n" + - "UpResponse\"g\n" + + "UpResponse\"\x9f\x01\n" + "\rStatusRequest\x12,\n" + "\x11getFullPeerStatus\x18\x01 \x01(\bR\x11getFullPeerStatus\x12(\n" + - "\x0fshouldRunProbes\x18\x02 \x01(\bR\x0fshouldRunProbes\"\x82\x01\n" + + "\x0fshouldRunProbes\x18\x02 \x01(\bR\x0fshouldRunProbes\x126\n" + + "\x16waitForConnectingShift\x18\x03 \x01(\bR\x16waitForConnectingShift\"\x82\x01\n" + "\x0eStatusResponse\x12\x16\n" + "\x06status\x18\x01 \x01(\tR\x06status\x122\n" + "\n" + diff --git a/client/proto/daemon.proto b/client/proto/daemon.proto index 0cd3579b9..6df768ec0 100644 --- a/client/proto/daemon.proto +++ b/client/proto/daemon.proto @@ -186,6 +186,7 @@ message UpResponse {} message StatusRequest{ bool getFullPeerStatus = 1; bool shouldRunProbes = 2; + bool waitForConnectingShift = 3; } message StatusResponse{ diff --git a/client/server/server.go b/client/server/server.go index fae342f78..a25c170c0 100644 --- a/client/server/server.go +++ b/client/server/server.go @@ -119,14 +119,12 @@ func (s *Server) Start() error { // if current state contains any error, return it // in all other cases we can continue execution only if status is idle and up command was // not in the progress or already successfully established connection. - status, err := state.Status() + _, err := state.Status() if err != nil { return err } - if status != internal.StatusIdle { - return nil - } + state.Set(internal.StatusConnecting) ctx, cancel := context.WithCancel(s.rootCtx) s.actCancel = cancel @@ -961,6 +959,30 @@ func (s *Server) sendLogoutRequestWithConfig(ctx context.Context, config *profil return mgmClient.Logout() } +func waitStateShift(ctx context.Context) { + timer := time.NewTimer(3 * time.Second) + defer timer.Stop() + for { + select { + case <-ctx.Done(): + timer.Stop() + return + case <-timer.C: + timer.Stop() + return + default: + status, err := internal.CtxGetState(ctx).Status() + if err != nil { + log.Errorf("failed to get status: %v", err) + return + } + if status != internal.StatusConnecting { + return + } + } + } +} + // Status returns the daemon status func (s *Server) Status( ctx context.Context, @@ -973,6 +995,10 @@ func (s *Server) Status( s.mutex.Lock() defer s.mutex.Unlock() + if msg.WaitForConnectingShift { + waitStateShift(s.rootCtx) + } + status, err := internal.CtxGetState(s.rootCtx).Status() if err != nil { return nil, err