Skip to content

Commit

Permalink
use context not docker timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Aug 30, 2017
1 parent f341119 commit 3ebb4b7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions cluster/calcium/remove_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,16 @@ func (c *calcium) removeOneContainer(container *types.Container, info enginetype
log.Errorf("Run exec at %s error: %s", BEFORE_STOP, err.Error())
}

if err = container.Engine.ContainerStop(context.Background(), info.ID, &c.config.GlobalTimeout); err != nil {
// 这里 block 的问题很严重,按照目前的配置是 5 分钟一级的 block
// 一个简单的处理方法是相信 ctx 不相信 docker 自身的处理
// 另外我怀疑 docker 自己的 timeout 实现是完全的等 timeout 而非结束了就退出
ctx, cancel := context.WithTimeout(context.Background(), c.config.GlobalTimeout)
defer cancel()
if err = container.Engine.ContainerStop(ctx, info.ID, nil); err != nil {
log.Errorf("Error during ContainerStop: %s", err.Error())
return err
}
log.Debugf("[removeOneContainer] Container stopped %s", info.ID)

rmOpts := enginetypes.ContainerRemoveOptions{
RemoveVolumes: true,
Expand All @@ -161,12 +167,9 @@ func (c *calcium) removeOneContainer(container *types.Container, info enginetype
log.Errorf("Error during ContainerRemove: %s", err.Error())
return err
}
log.Debugf("[removeOneContainer] Container removed %s", info.ID)

if err = c.store.RemoveContainer(info.ID, container); err != nil {
log.Errorf("Error during remove etcd data: %s", err.Error())
return err
}
return nil
return c.store.RemoveContainer(info.ID, container)
}

// 同步地删除容器, 在某些需要等待的场合异常有用!
Expand Down

0 comments on commit 3ebb4b7

Please sign in to comment.