-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: timeout zombie processes in alpine based containers (#97)
- Loading branch information
Showing
13 changed files
with
383 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0. | ||
*/ | ||
|
||
package handlers | ||
|
||
import ( | ||
"errors" | ||
"github.com/traas-stack/holoinsight-agent/cmd/containerhelper/model" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
const ( | ||
countLimit = 100 | ||
) | ||
|
||
// Count the number of zombie processes | ||
func countZombiesHandler(_ string, resp *model.Resp) error { | ||
count := 0 | ||
filepath.Walk("/proc", func(path string, info fs.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if !info.IsDir() { | ||
return nil | ||
} | ||
if _, err := strconv.ParseInt(info.Name(), 10, 32); err != nil { | ||
return nil | ||
} | ||
content, err := os.ReadFile(filepath.Join(path, "/status")) | ||
if err != nil { | ||
return nil | ||
} | ||
lines := strings.Split(string(content), "\n") | ||
for _, line := range lines { | ||
if strings.HasPrefix(line, "State:") { | ||
if strings.Contains(line, "zombie") { | ||
count++ | ||
} | ||
break | ||
} | ||
} | ||
if count > countLimit { | ||
return errors.New("SkipAll") | ||
} | ||
return filepath.SkipDir | ||
}) | ||
resp.Data = count | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
# docs: count zombies processes | ||
COUNT_LIMIT=100 | ||
|
||
count=0 | ||
for i in /proc/*; do | ||
b=`basename $i` | ||
if [ -e "$i/status" ]; then | ||
if grep 'State: Z (zombie)' "$i/status" >/dev/null 2>&1; then | ||
count=`expr $count + 1` | ||
if [ "$count" -gt "$COUNT_LIMIT" ]; then | ||
break | ||
fi | ||
fi | ||
fi | ||
done | ||
|
||
echo $count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0. | ||
*/ | ||
|
||
package criutils | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"github.com/spf13/cast" | ||
"github.com/traas-stack/holoinsight-agent/cmd/containerhelper/model" | ||
"github.com/traas-stack/holoinsight-agent/pkg/core" | ||
"github.com/traas-stack/holoinsight-agent/pkg/cri" | ||
) | ||
|
||
func CountZombies(i cri.Interface, ctx context.Context, c *cri.Container) (int, error) { | ||
r, err := i.Exec(ctx, c, cri.ExecRequest{ | ||
Cmd: []string{core.HelperToolPath, "countZombies"}, | ||
}) | ||
if err != nil { | ||
return 0, err | ||
} | ||
resp := &model.Resp{} | ||
if err := json.NewDecoder(r.Stdout).Decode(resp); err != nil { | ||
return 0, err | ||
} | ||
return cast.ToIntE(resp.Data) | ||
} |
Oops, something went wrong.