Skip to content

Commit

Permalink
Fix transaction error
Browse files Browse the repository at this point in the history
  • Loading branch information
whywaita committed Feb 28, 2024
1 parent 51a576c commit 8a552bb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions server/pkg/api/server_add_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,27 @@ func (s *ShoesLXDMultiServer) AddInstance(ctx context.Context, req *pb.AddInstan
if err != nil {
// Do rollback
l.Info("failed to start instance, will delete", "err", err.Error(), "failed_method", "client.UpdateInstanceState()")
if _, err := client.DeleteInstance(instanceName); err != nil {
op, err := client.DeleteInstance(instanceName)
if err != nil {
l.Warn("failed to delete instance", "err", err.Error())
}
if err := op.Wait(); err != nil {
l.Warn("failed to wait deleting instance", "err", err.Error())
}

return nil, status.Errorf(codes.Internal, "failed to start instance: %+v", err)
}
if err := op.Wait(); err != nil && !strings.EqualFold(err.Error(), "The instance is already running") {
// Do rollback
l.Info("failed to start instance, will delete", "err", err.Error(), "failed_method", "op.Wait()")
if _, err := client.DeleteInstance(instanceName); err != nil {
op, err := client.DeleteInstance(instanceName)
if err != nil {
l.Warn("failed to delete instance", "err", err.Error())
}
if err := op.Wait(); err != nil {
l.Warn("failed to wait deleting instance", "err", err.Error())
}

return nil, status.Errorf(codes.Internal, "failed to wait starting instance: %+v", err)
}

Expand Down

0 comments on commit 8a552bb

Please sign in to comment.