I have used signal handler to handle SIGTERM
, SIGINT
signals. When grpc server is up and running I issue sudo kill -15 [PID]
command and I don’t see my graceful shutdown log reports and also I get:
[1] 41983 terminated go run mypkg/main.go
Now when I use netstat it reports that port number 50051 is open and I cannot run my server as the port number is busy.
What I have done:
func main() {
flag.Parse()
fmt.Printf("Starting up server on 0.0.0.0:%v...\n", *port)
server := NewServer(fmt.Sprintf("0.0.0.0:%d", *port))
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
server.Run()
wg.Done()
}()
// Signal handling and graceful shutdown of gRPC server
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
<-signalChan
server.Stop()
wg.Wait()
}
server.Stop()
function is used to stop the grpc server, grpcServer.GracefulStop()
, and log some data.
When I issue CTRL+C
everything works as expected. Why on sudo kill -15
I this behavior?