Fix handling of interrupts (#125)

This commit is contained in:
subham sarkar 2020-09-23 04:58:41 +05:30 committed by GitHub
parent 83c2ede294
commit 233968d71d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 12 deletions

View file

@ -95,17 +95,16 @@ const (
serverDone = 2
)
func handleCtrlC(toStop chan int) {
// handleInterrupt handles os.Interrupt
// os.Interrupt guaranteed to be present on all systems
func handleInterrupt(toStop chan<- int) {
sigChan := make(chan os.Signal)
signal.Notify(sigChan, os.Interrupt, os.Kill)
// TODO: Handle graceful shutdown in containers as well
// by handling syscall.SIGTERM
signal.Notify(sigChan, os.Interrupt)
go func() {
sig := <-sigChan
switch sig {
case os.Interrupt:
fallthrough
case os.Kill:
toStop <- interrupt
}
<-sigChan
toStop <- interrupt
}()
}
@ -163,7 +162,7 @@ func runTest(test *ethrTest, d time.Duration) {
toStop := make(chan int, 1)
runDurationTimer(d, toStop)
clientWatchControlChannel(test, toStop)
handleCtrlC(toStop)
handleInterrupt(toStop)
reason := <-toStop
close(test.done)
sendSessionMsg(test.enc, &EthrMsg{})

View file

@ -41,7 +41,7 @@ func xcRunTest(test *ethrTest, d, g time.Duration) {
test.isActive = true
toStop := make(chan int, 1)
runDurationTimer(d, toStop)
handleCtrlC(toStop)
handleInterrupt(toStop)
reason := <-toStop
close(test.done)
stopStatsTimer()

View file

@ -21,7 +21,7 @@ func runXServer(testParam EthrTestParam, serverParam ethrServerParam) {
// runHTTPSBandwidthServer()
startStatsTimer()
toStop := make(chan int, 1)
handleCtrlC(toStop)
handleInterrupt(toStop)
<-toStop
ui.printMsg("Ethr done, received interrupt signal.")
}