Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix plugin crash due to nil in container info #1247

Merged
merged 9 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions pkg/helper/docker_center.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,14 +625,22 @@ 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")
for i := 0; i < 10; 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 == 9 {
quzard marked this conversation as resolved.
Show resolved Hide resolved
logger.Error(context.Background(), "DOCKER_CENTER_ALARM", "[CRIRuntime] create cri-runtime client failed")
}
}

}
if ok, err := util.PathExists(DefaultLogtailMountPath); err == nil {
if !ok {
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, err:%v", err)
quzard marked this conversation as resolved.
Show resolved Hide resolved
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")
continue
}
if dockerContainer.Status() != ContainerStatusRunning {
continue
}
cw.containers[c.GetId()] = &innerContainerInfo{
Expand Down
Loading