Skip to content

Commit

Permalink
Merge pull request #2757 from Random-Liu/cherry-pick-#2624
Browse files Browse the repository at this point in the history
[release/1.1] Backport: modify lock location of exec delete avoid exec hang
  • Loading branch information
crosbymichael committed Nov 2, 2018
2 parents c018c6e + deeaac9 commit 68a2cbc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions linux/proc/exec_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ func (s *execCreatedState) Start(ctx context.Context) error {
}

func (s *execCreatedState) Delete(ctx context.Context) error {
s.p.mu.Lock()
defer s.p.mu.Unlock()
if err := s.p.delete(ctx); err != nil {
return err
}
s.p.mu.Lock()
defer s.p.mu.Unlock()
return s.transition("deleted")
}

Expand Down Expand Up @@ -168,11 +168,11 @@ func (s *execStoppedState) Start(ctx context.Context) error {
}

func (s *execStoppedState) Delete(ctx context.Context) error {
s.p.mu.Lock()
defer s.p.mu.Unlock()
if err := s.p.delete(ctx); err != nil {
return err
}
s.p.mu.Lock()
defer s.p.mu.Unlock()
return s.transition("deleted")
}

Expand Down
6 changes: 4 additions & 2 deletions linux/shim/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,21 @@ func (s *Service) Delete(ctx context.Context, r *ptypes.Empty) (*shimapi.DeleteR

// DeleteProcess deletes an exec'd process
func (s *Service) DeleteProcess(ctx context.Context, r *shimapi.DeleteProcessRequest) (*shimapi.DeleteResponse, error) {
s.mu.Lock()
defer s.mu.Unlock()
if r.ID == s.id {
return nil, status.Errorf(codes.InvalidArgument, "cannot delete init process with DeleteProcess")
}
s.mu.Lock()
p := s.processes[r.ID]
s.mu.Unlock()
if p == nil {
return nil, errors.Wrapf(errdefs.ErrNotFound, "process %s", r.ID)
}
if err := p.Delete(ctx); err != nil {
return nil, err
}
s.mu.Lock()
delete(s.processes, r.ID)
s.mu.Unlock()
return &shimapi.DeleteResponse{
ExitStatus: uint32(p.ExitStatus()),
ExitedAt: p.ExitedAt(),
Expand Down

0 comments on commit 68a2cbc

Please sign in to comment.