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

Make worker kill better #107

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all 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
6 changes: 3 additions & 3 deletions server/internal/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os/exec"
"strconv"
"strings"
"syscall"
"time"

"github.com/gogf/gf/container/gmap"
Expand Down Expand Up @@ -71,10 +72,9 @@ func (w *Worker) start(req *StartReq) (err error) {
func (w *Worker) stop(requestId string, channelName string) (err error) {
slog.Info("Worker stop start", "channelName", channelName, "requestId", requestId, logTag)

shell := fmt.Sprintf("kill -9 %d", w.Pid)
output, err := exec.Command("sh", "-c", shell).CombinedOutput()
err = syscall.Kill(w.Pid, syscall.SIGTERM)
if err != nil {
slog.Error("Worker kill failed", "err", err, "output", output, "channelName", channelName, "worker", w, "requestId", requestId, logTag)
slog.Error("Worker kill failed", "err", err, "channelName", channelName, "worker", w, "requestId", requestId, logTag)
return
}

Expand Down