Skip to content

Conversation

@Zllinc
Copy link
Collaborator

@Zllinc Zllinc commented Dec 25, 2025

No description provided.

@Zllinc Zllinc force-pushed the fix-lvm branch 2 times, most recently from 9653ea1 to e80bcda Compare December 25, 2025 08:37
Signed-off-by: Zllinc <2965202581@qq.com>
Comment on lines 296 to 302
done := make(chan error, 1)
go func() {
done <- cmd.Wait()
}()

select {
case err := <-done:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we can directly use ctx to check for timeouts

Comment on lines 320 to 330
pgid, err := syscall.Getpgid(cmd.Process.Pid)
if err != nil {
klog.Warningf("lvm: failed to get process group ID for PID %d: %v",
cmd.Process.Pid, err)
// If we can't get process group, kill the process directly
cmd.Process.Signal(syscall.SIGTERM)
} else {
// Send SIGTERM to the entire process group (negative PID means process group)
if err := syscall.Kill(-pgid, syscall.SIGTERM); err != nil {
klog.Warningf("lvm: failed to send SIGTERM to process group %d: %v", pgid, err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmd.Cancel = func() error {
fmt.Println("Sending SIGTERM...")
return cmd.Process.Signal(syscall.SIGTERM)
}

// Wait for 10 seconds for the process to exit gracefully; send SIGKILL after timeout
cmd.WaitDelay = 10 * time.Second

You can use the command like this

klog.Warningf("lvm: command %s %v timed out, sending SIGTERM", command, args)

if cmd.Process != nil {
pgid, err := syscall.Getpgid(cmd.Process.Pid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pgid should equal Process.Pid

// Wait delay to send SIGKILL to the process group
cmd.WaitDelay = CommandGraceTimeout

err := cmd.Run()
Copy link
Member

@zijiren233 zijiren233 Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need add this after cmd.Run

    if err != nil && errors.Is(ctx.Err(), context.DeadlineExceeded) {
        if cmd.Process != nil {
            pgid := cmd.Process.Pid
            syscall.Kill(-pgid, syscall.SIGKILL)
        }
    }

@dinoallo dinoallo merged commit 2d93bd3 into labring:v1.7 Dec 26, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants