Merge pull request #2624 from Ace-Tang/fix_delete_lock

fix: modify lock location of exec delete avoid exec hang
This commit is contained in:
Phil Estes 2018-09-11 10:26:32 -04:00 committed by GitHub
commit ed2bf6dd8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View File

@ -60,11 +60,11 @@ func (s *execCreatedState) Start(ctx context.Context) error {
} }
func (s *execCreatedState) Delete(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 { if err := s.p.delete(ctx); err != nil {
return err return err
} }
s.p.mu.Lock()
defer s.p.mu.Unlock()
return s.transition("deleted") return s.transition("deleted")
} }
@ -168,11 +168,11 @@ func (s *execStoppedState) Start(ctx context.Context) error {
} }
func (s *execStoppedState) Delete(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 { if err := s.p.delete(ctx); err != nil {
return err return err
} }
s.p.mu.Lock()
defer s.p.mu.Unlock()
return s.transition("deleted") return s.transition("deleted")
} }

View File

@ -224,19 +224,21 @@ func (s *Service) Delete(ctx context.Context, r *ptypes.Empty) (*shimapi.DeleteR
// DeleteProcess deletes an exec'd process // DeleteProcess deletes an exec'd process
func (s *Service) DeleteProcess(ctx context.Context, r *shimapi.DeleteProcessRequest) (*shimapi.DeleteResponse, error) { 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 { if r.ID == s.id {
return nil, status.Errorf(codes.InvalidArgument, "cannot delete init process with DeleteProcess") return nil, status.Errorf(codes.InvalidArgument, "cannot delete init process with DeleteProcess")
} }
s.mu.Lock()
p := s.processes[r.ID] p := s.processes[r.ID]
s.mu.Unlock()
if p == nil { if p == nil {
return nil, errors.Wrapf(errdefs.ErrNotFound, "process %s", r.ID) return nil, errors.Wrapf(errdefs.ErrNotFound, "process %s", r.ID)
} }
if err := p.Delete(ctx); err != nil { if err := p.Delete(ctx); err != nil {
return nil, err return nil, err
} }
s.mu.Lock()
delete(s.processes, r.ID) delete(s.processes, r.ID)
s.mu.Unlock()
return &shimapi.DeleteResponse{ return &shimapi.DeleteResponse{
ExitStatus: uint32(p.ExitStatus()), ExitStatus: uint32(p.ExitStatus()),
ExitedAt: p.ExitedAt(), ExitedAt: p.ExitedAt(),