func gracefulExit(rcvr *receiver.Receiver, serviceMgr *serviceManager) { log.Printf("Gracefully exiting...") quitting = true if gracefulChildPid == 0 { rcvr.ClusterReady(false) // triggers a transition // Allow enough time for a transition to start time.Sleep(500 * time.Millisecond) // TODO This is a hack } log.Printf("Waiting for all TCP connections to finish...") serviceMgr.closeListeners() log.Printf("TCP connections finished.") // Stop the receiver rcvr.Stop() if gracefulChildPid != 0 { // let the child know the data is flushed syscall.Kill(gracefulChildPid, syscall.SIGUSR1) } }