fix(host): adjust timeout for stopping container (#21458)

This commit is contained in:
Zexi Li
2024-10-24 20:35:33 +08:00
committed by GitHub
parent df6645c487
commit 2e07e9204c
2 changed files with 10 additions and 8 deletions
+3 -6
View File
@@ -352,7 +352,7 @@ func (s *sPodGuestInstance) SyncStatus(reason string) {
ctx := context.Background()
if status == computeapi.VM_READY {
// remove pod
if err := s.stopPod(ctx, 1); err != nil {
if err := s.stopPod(ctx, 5); err != nil {
log.Warningf("stop cri pod when sync status: %s: %v", s.Id, err)
}
}
@@ -893,7 +893,7 @@ func (s *sPodGuestInstance) setPodCgroupResources(criId string, memMB int64, cpu
func (s *sPodGuestInstance) ensurePodRemoved(ctx context.Context, timeout int64) error {
if timeout == 0 {
timeout = 5
timeout = 15
}
ctx, cancel := context.WithTimeout(ctx, time.Duration(timeout)*time.Second)
@@ -929,7 +929,7 @@ func (s *sPodGuestInstance) stopPod(ctx context.Context, timeout int64) error {
return errors.Wrapf(err, "umount pod volumes")
}
if timeout == 0 {
timeout = 5
timeout = 15
}
return s.ensurePodRemoved(ctx, timeout)
@@ -1154,9 +1154,6 @@ func (s *sPodGuestInstance) StopContainer(ctx context.Context, userCred mcclient
return nil, errors.Wrapf(err, "unmount shm %s", name)
}
}
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
if err := s.getCRI().StopContainer(ctx, criId, timeout, true); err != nil {
if !IsContainerNotFoundError(err) {
return nil, errors.Wrap(err, "CRI.StopContainer")
+7 -2
View File
@@ -330,10 +330,13 @@ func (c crictl) RemovePod(ctx context.Context, podId string) error {
}
func (c crictl) StopContainer(ctx context.Context, ctrId string, timeout int64, tryRemove bool) error {
maxTries := 5
interval := 3 * time.Second
maxTries := 10
interval := 5 * time.Second
errs := []error{}
for tries := 0; tries < maxTries; tries++ {
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
err := c.stopContainer(ctx, ctrId, timeout)
if err == nil {
return nil
@@ -347,6 +350,8 @@ func (c crictl) StopContainer(ctx context.Context, ctrId string, timeout int64,
}
if tryRemove {
// try force remove container
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
if err := c.RemoveContainer(ctx, ctrId); err != nil {
errs = append(errs, errors.Wrapf(err, "try remove container %s", ctrId))
} else {