Why "RegisterInterruptHandler is a no-op on windows" #16768
Answered
by
tjungblu
Equationzhao
asked this question in
Q&A
-
in the interrupt_windows.go, the RegisterInterruptHandler and HandleInterrupts are empty. but the UNIX one listens to the int and term signals and does something to kill those process Why? windowspackage osutil
import (
"os"
"go.uber.org/zap"
)
type InterruptHandler func()
// RegisterInterruptHandler is a no-op on windows
func RegisterInterruptHandler(h InterruptHandler) {}
// HandleInterrupts is a no-op on windows
func HandleInterrupts(*zap.Logger) {}
// Exit calls os.Exit
func Exit(code int) {
os.Exit(code)
} unix// RegisterInterruptHandler registers a new InterruptHandler. Handlers registered
// after interrupt handing was initiated will not be executed.
func RegisterInterruptHandler(h InterruptHandler) {
interruptRegisterMu.Lock()
defer interruptRegisterMu.Unlock()
interruptHandlers = append(interruptHandlers, h)
}
// HandleInterrupts calls the handler functions on receiving a SIGINT or SIGTERM.
func HandleInterrupts(lg *zap.Logger) {
verify.Assert(lg != nil, "the logger should not be nil")
notifier := make(chan os.Signal, 1)
signal.Notify(notifier, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-notifier
interruptRegisterMu.Lock()
ihs := make([]InterruptHandler, len(interruptHandlers))
copy(ihs, interruptHandlers)
interruptRegisterMu.Unlock()
interruptExitMu.Lock()
lg.Info("received signal; shutting down", zap.String("signal", sig.String()))
for _, h := range ihs {
h()
}
signal.Stop(notifier)
pid := syscall.Getpid()
// exit directly if it is the "init" process, since the kernel will not help to kill pid 1.
if pid == 1 {
os.Exit(0)
}
setDflSignal(sig.(syscall.Signal))
syscall.Kill(pid, sig.(syscall.Signal))
}()
}
// Exit relays to os.Exit if no interrupt handlers are running, blocks otherwise.
func Exit(code int) {
interruptExitMu.Lock()
os.Exit(code)
} |
Beta Was this translation helpful? Give feedback.
Answered by
tjungblu
Oct 24, 2023
Replies: 1 comment
-
long story short: because it was implemented that way more than 8 years ago in #2305 and we don't really support Windows as well: https://etcd.io/docs/v3.5/op-guide/supported-platform/ |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Equationzhao
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
long story short: because it was implemented that way more than 8 years ago in #2305
and we don't really support Windows as well: https://etcd.io/docs/v3.5/op-guide/supported-platform/