1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-12 02:41:05 +00:00

👶 Close child procs when PID gets killed

This commit is contained in:
Fenny 2020-07-14 02:35:35 +02:00
parent bb5ad54658
commit fe826a782d

View File

@ -6,9 +6,11 @@ import (
"net"
"os"
"os/exec"
"os/signal"
"runtime"
"strconv"
"strings"
"syscall"
"time"
)
@ -94,6 +96,17 @@ func (app *App) prefork(addr string, tlsconfig ...*tls.Config) (err error) {
app.startupMessage(addr, len(tlsconfig) > 0, ","+strings.Join(pids, ","))
}
// kill child procs when master exits
c := make(chan os.Signal)
signal.Notify(c, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT)
go func() {
<-c
for _, proc := range childs {
_ = proc.Process.Kill()
}
os.Exit(1)
}()
// return error if child crashes
for sig := range channel {
return sig.err