-
Notifications
You must be signed in to change notification settings - Fork 2
fix(devbox): add lvm timeout #20
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
Conversation
9653ea1 to
e80bcda
Compare
Signed-off-by: Zllinc <2965202581@qq.com>
snapshots/devbox/lvm/lvm.go
Outdated
| done := make(chan error, 1) | ||
| go func() { | ||
| done <- cmd.Wait() | ||
| }() | ||
|
|
||
| select { | ||
| case err := <-done: |
There was a problem hiding this comment.
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
snapshots/devbox/lvm/lvm.go
Outdated
| 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) | ||
| } |
There was a problem hiding this comment.
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.SecondYou can use the command like this
snapshots/devbox/lvm/lvm.go
Outdated
| klog.Warningf("lvm: command %s %v timed out, sending SIGTERM", command, args) | ||
|
|
||
| if cmd.Process != nil { | ||
| pgid, err := syscall.Getpgid(cmd.Process.Pid) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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)
}
}
No description provided.