mirror of
https://github.com/tuna/tunasync.git
synced 2025-04-20 20:22:46 +00:00
fix(worker): cgroup hook now ensure child progresses are killed
This commit is contained in:
parent
c8af09f129
commit
437acd3f01
@ -2,18 +2,20 @@ package worker
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
"github.com/codeskyblue/go-sh"
|
"github.com/codeskyblue/go-sh"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cgSubsystem string = "cpu"
|
var cgSubsystem = "cpu"
|
||||||
|
|
||||||
type cgroupHook struct {
|
type cgroupHook struct {
|
||||||
emptyHook
|
emptyHook
|
||||||
@ -82,23 +84,43 @@ func (c *cgroupHook) killAll() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
name := c.provider.Name()
|
name := c.provider.Name()
|
||||||
taskFile, err := os.Open(filepath.Join(c.basePath, cgSubsystem, c.baseGroup, name, "tasks"))
|
|
||||||
if err != nil {
|
readTaskList := func() ([]int, error) {
|
||||||
return err
|
taskList := []int{}
|
||||||
|
taskFile, err := os.Open(filepath.Join(c.basePath, cgSubsystem, c.baseGroup, name, "tasks"))
|
||||||
|
if err != nil {
|
||||||
|
return taskList, err
|
||||||
|
}
|
||||||
|
defer taskFile.Close()
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(taskFile)
|
||||||
|
for scanner.Scan() {
|
||||||
|
pid, err := strconv.Atoi(scanner.Text())
|
||||||
|
if err != nil {
|
||||||
|
return taskList, err
|
||||||
|
}
|
||||||
|
taskList = append(taskList, pid)
|
||||||
|
}
|
||||||
|
return taskList, nil
|
||||||
}
|
}
|
||||||
defer taskFile.Close()
|
|
||||||
taskList := []int{}
|
for i := 0; i < 4; i++ {
|
||||||
scanner := bufio.NewScanner(taskFile)
|
if i == 3 {
|
||||||
for scanner.Scan() {
|
return errors.New("Unable to kill all child tasks")
|
||||||
pid, err := strconv.Atoi(scanner.Text())
|
}
|
||||||
|
taskList, err := readTaskList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
taskList = append(taskList, pid)
|
if len(taskList) == 0 {
|
||||||
}
|
return nil
|
||||||
for _, pid := range taskList {
|
}
|
||||||
logger.Debugf("Killing process: %d", pid)
|
for _, pid := range taskList {
|
||||||
unix.Kill(pid, syscall.SIGKILL)
|
logger.Debugf("Killing process: %d", pid)
|
||||||
|
unix.Kill(pid, syscall.SIGKILL)
|
||||||
|
}
|
||||||
|
// sleep 10ms for the first round, and 1.01s, 2.01s, 3.01s for the rest
|
||||||
|
time.Sleep(time.Duration(i)*time.Second + 10*time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user