Skip to content

Commit deeaac9

Browse files
Ace-TangRandom-Liu
authored andcommitted
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 c018c6e commit deeaac9

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

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

linux/shim/service.go

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

197197
// DeleteProcess deletes an exec'd process
198198
func (s *Service) DeleteProcess(ctx context.Context, r *shimapi.DeleteProcessRequest) (*shimapi.DeleteResponse, error) {
199-
s.mu.Lock()
200-
defer s.mu.Unlock()
201199
if r.ID == s.id {
202200
return nil, status.Errorf(codes.InvalidArgument, "cannot delete init process with DeleteProcess")
203201
}
202+
s.mu.Lock()
204203
p := s.processes[r.ID]
204+
s.mu.Unlock()
205205
if p == nil {
206206
return nil, errors.Wrapf(errdefs.ErrNotFound, "process %s", r.ID)
207207
}
208208
if err := p.Delete(ctx); err != nil {
209209
return nil, err
210210
}
211+
s.mu.Lock()
211212
delete(s.processes, r.ID)
213+
s.mu.Unlock()
212214
return &shimapi.DeleteResponse{
213215
ExitStatus: uint32(p.ExitStatus()),
214216
ExitedAt: p.ExitedAt(),

0 commit comments

Comments
 (0)