Skip to content

Commit

Permalink
fix dockerContainer nil (#1247)
Browse files Browse the repository at this point in the history
* fix nil

* 重试机制

* fix

* add retryTimes

* logger Container Info

* Container Info
  • Loading branch information
quzard committed Nov 28, 2023
1 parent 5913feb commit 8462532
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
22 changes: 15 additions & 7 deletions pkg/helper/docker_center.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,13 +625,21 @@ func getDockerCenterInstance() *DockerCenter {
dockerCenterInstance.imageCache = make(map[string]string)
dockerCenterInstance.containerMap = make(map[string]*DockerInfoDetail)
if IsCRIRuntimeValid(containerdUnixSocket) {
var err error
criRuntimeWrapper, err = NewCRIRuntimeWrapper(dockerCenterInstance)
if err != nil {
logger.Errorf(context.Background(), "DOCKER_CENTER_ALARM", "[CRIRuntime] creare cri-runtime client error: %v", err)
criRuntimeWrapper = nil
} else {
logger.Infof(context.Background(), "[CRIRuntime] create cri-runtime client successfully")
retryTimes := 10
for i := 0; i < retryTimes; i++ {
var err error
criRuntimeWrapper, err = NewCRIRuntimeWrapper(dockerCenterInstance)
if err != nil {
logger.Errorf(context.Background(), "DOCKER_CENTER_ALARM", "[CRIRuntime] creare cri-runtime client error: %v", err)
criRuntimeWrapper = nil
} else {
logger.Infof(context.Background(), "[CRIRuntime] create cri-runtime client successfully")
break
}
time.Sleep(time.Second * 1)
if i == retryTimes-1 {
logger.Error(context.Background(), "DOCKER_CENTER_ALARM", "[CRIRuntime] create cri-runtime client failed")
}
}
}
if ok, err := util.PathExists(DefaultLogtailMountPath); err == nil {
Expand Down
10 changes: 7 additions & 3 deletions pkg/helper/docker_cri_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,15 @@ func (cw *CRIRuntimeWrapper) fetchAll() error {
}

dockerContainer, _, _, err := cw.createContainerInfo(c.GetId())
if dockerContainer.Status() != ContainerStatusRunning {
if err != nil {
logger.Errorf(context.Background(), "CREATE_CONTAINERD_INFO_ALARM", "Create container info from cri-runtime error, Container Info: %+v, err: %v", c, err)
continue
}
if err != nil {
logger.Debug(context.Background(), "Create container info from cri-runtime error", err)
if dockerContainer == nil || dockerContainer.ContainerInfo.ContainerJSONBase == nil {
logger.Error(context.Background(), "CREATE_CONTAINERD_INFO_ALARM", "Create container info from cri-runtime error, Container Info:%+v", c)
continue
}
if dockerContainer.Status() != ContainerStatusRunning {
continue
}
cw.containers[c.GetId()] = &innerContainerInfo{
Expand Down

0 comments on commit 8462532

Please sign in to comment.