Skip to content

Commit 079292e

Browse files
committed
fix: modify lock location of exec delete
func (e *execProcess) delete(ctx context.Context) error { e.wg.Wait() ... } delete exec process will wait for io copy finish, if wait here, other process can not get lock of shim service. 1. apply lock around s.transition() calls in the Delete methods. 2. put lock after wait io copy in exec Delete. Signed-off-by: Ace-Tang <[email protected]>
1 parent 6ca8355 commit 079292e

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)