Skip to content

Commit ed2bf6d

Browse files
authored
Merge pull request #2624 from Ace-Tang/fix_delete_lock
fix: modify lock location of exec delete avoid exec hang
2 parents 1597270 + 079292e commit ed2bf6d

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

runtime/v1/linux/proc/exec_state.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ func (s *execCreatedState) Start(ctx context.Context) error {
6060
}
6161

6262
func (s *execCreatedState) Delete(ctx context.Context) error {
63-
s.p.mu.Lock()
64-
defer s.p.mu.Unlock()
6563
if err := s.p.delete(ctx); err != nil {
6664
return err
6765
}
66+
s.p.mu.Lock()
67+
defer s.p.mu.Unlock()
6868
return s.transition("deleted")
6969
}
7070

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

170170
func (s *execStoppedState) Delete(ctx context.Context) error {
171-
s.p.mu.Lock()
172-
defer s.p.mu.Unlock()
173171
if err := s.p.delete(ctx); err != nil {
174172
return err
175173
}
174+
s.p.mu.Lock()
175+
defer s.p.mu.Unlock()
176176
return s.transition("deleted")
177177
}
178178

runtime/v1/shim/service.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,19 +224,21 @@ func (s *Service) Delete(ctx context.Context, r *ptypes.Empty) (*shimapi.DeleteR
224224

225225
// DeleteProcess deletes an exec'd process
226226
func (s *Service) DeleteProcess(ctx context.Context, r *shimapi.DeleteProcessRequest) (*shimapi.DeleteResponse, error) {
227-
s.mu.Lock()
228-
defer s.mu.Unlock()
229227
if r.ID == s.id {
230228
return nil, status.Errorf(codes.InvalidArgument, "cannot delete init process with DeleteProcess")
231229
}
230+
s.mu.Lock()
232231
p := s.processes[r.ID]
232+
s.mu.Unlock()
233233
if p == nil {
234234
return nil, errors.Wrapf(errdefs.ErrNotFound, "process %s", r.ID)
235235
}
236236
if err := p.Delete(ctx); err != nil {
237237
return nil, err
238238
}
239+
s.mu.Lock()
239240
delete(s.processes, r.ID)
241+
s.mu.Unlock()
240242
return &shimapi.DeleteResponse{
241243
ExitStatus: uint32(p.ExitStatus()),
242244
ExitedAt: p.ExitedAt(),

0 commit comments

Comments
 (0)