diff --git a/config/graceful_shutdown.go b/config/graceful_shutdown.go index 0b39d111503377df318b4cfbf6243126183735d9..1119c3a531668c08101b86b89402a02142c6ac86 100644 --- a/config/graceful_shutdown.go +++ b/config/graceful_shutdown.go @@ -49,17 +49,15 @@ import ( * syscall.SIGEMT cannot be found in CI * It's seems that the Unix/Linux does not have the signal SIGSTKFLT. https://github.com/golang/go/issues/33381 * So this signal will be ignored. - * + * The signals are different on different platforms. + * We define them by using 'package build' feature https://golang.org/pkg/go/build/ */ func GracefulShutdownInit() { signals := make(chan os.Signal, 1) - signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGKILL, syscall.SIGSTOP, - syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP, - syscall.SIGABRT, syscall.SIGSYS, - ) + signal.Notify(signals, ShutdownSignals...) go func() { select { @@ -70,8 +68,9 @@ func GracefulShutdownInit() { switch sig { // those signals' original behavior is exit with dump ths stack, so we try to keep the behavior + // syscall.SIGSYS will be ignored. It's not supported in windows platform. case syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP, - syscall.SIGABRT, syscall.SIGSYS: + syscall.SIGABRT: debug.WriteHeapDump(os.Stdout.Fd()) default: time.AfterFunc(totalTimeout(), func() { diff --git a/config/graceful_shutdown_signal_unix.go b/config/graceful_shutdown_signal_unix.go new file mode 100644 index 0000000000000000000000000000000000000000..6333a00220f5857940b7e523e729b9c0c0b782d8 --- /dev/null +++ b/config/graceful_shutdown_signal_unix.go @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package config + +import ( + "os" + "syscall" +) + +var ShutdownSignals = []os.Signal{os.Interrupt, os.Kill, syscall.SIGKILL, syscall.SIGSTOP, + syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP, + syscall.SIGABRT, syscall.SIGSYS} diff --git a/config/graceful_shutdown_signal_windows.go b/config/graceful_shutdown_signal_windows.go new file mode 100644 index 0000000000000000000000000000000000000000..ff7a48113c14512e7874638911df0970cadf679e --- /dev/null +++ b/config/graceful_shutdown_signal_windows.go @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package config + +import ( + "os" + "syscall" +) + +var ShutdownSignals = []os.Signal{os.Interrupt, os.Kill, syscall.SIGKILL, + syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGILL, syscall.SIGTRAP, + syscall.SIGABRT}