mirror of
				https://github.com/kata-containers/kata-containers.git
				synced 2025-10-31 09:26:52 +00:00 
			
		
		
		
	shimv2: do not kill a stopped exec process
Same as containers, it is possible for an exec process to stop so quickly that containerd may send a parallel Kill request. We should just return success in such case. Fixes: #716 Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
		| @@ -681,20 +681,7 @@ func (s *service) Kill(ctx context.Context, r *taskAPI.KillRequest) (_ *ptypes.E | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// According to CRI specs, kubelet will call StopPodSandbox() | 	processStatus := c.status | ||||||
| 	// at least once before calling RemovePodSandbox, and this call |  | ||||||
| 	// is idempotent, and must not return an error if all relevant |  | ||||||
| 	// resources have already been reclaimed. And in that call it will |  | ||||||
| 	// send a SIGKILL signal first to try to stop the container, thus |  | ||||||
| 	// once the container has terminated, here should ignore this signal |  | ||||||
| 	// and return directly. |  | ||||||
| 	if signum == syscall.SIGKILL || signum == syscall.SIGTERM { |  | ||||||
| 		if c.status == task.StatusStopped { |  | ||||||
| 			shimLog.WithField("sandbox", s.sandbox.ID()).WithField("container", c.id).Debug("Container has already been stopped") |  | ||||||
| 			return empty, nil |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	processID := c.id | 	processID := c.id | ||||||
| 	if r.ExecID != "" { | 	if r.ExecID != "" { | ||||||
| 		execs, err := c.getExec(r.ExecID) | 		execs, err := c.getExec(r.ExecID) | ||||||
| @@ -710,6 +697,23 @@ func (s *service) Kill(ctx context.Context, r *taskAPI.KillRequest) (_ *ptypes.E | |||||||
| 			}).Debug("Id of exec process to be signalled is empty") | 			}).Debug("Id of exec process to be signalled is empty") | ||||||
| 			return empty, errors.New("The exec process does not exist") | 			return empty, errors.New("The exec process does not exist") | ||||||
| 		} | 		} | ||||||
|  | 		processStatus = execs.status | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// According to CRI specs, kubelet will call StopPodSandbox() | ||||||
|  | 	// at least once before calling RemovePodSandbox, and this call | ||||||
|  | 	// is idempotent, and must not return an error if all relevant | ||||||
|  | 	// resources have already been reclaimed. And in that call it will | ||||||
|  | 	// send a SIGKILL signal first to try to stop the container, thus | ||||||
|  | 	// once the container has terminated, here should ignore this signal | ||||||
|  | 	// and return directly. | ||||||
|  | 	if (signum == syscall.SIGKILL || signum == syscall.SIGTERM) && processStatus == task.StatusStopped { | ||||||
|  | 		shimLog.WithFields(logrus.Fields{ | ||||||
|  | 			"sandbox":   s.sandbox.ID(), | ||||||
|  | 			"container": c.id, | ||||||
|  | 			"exec-id":   r.ExecID, | ||||||
|  | 		}).Debug("process has already stopped") | ||||||
|  | 		return empty, nil | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return empty, s.sandbox.SignalProcess(c.id, processID, signum, r.All) | 	return empty, s.sandbox.SignalProcess(c.id, processID, signum, r.All) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user