mirror of
https://github.com/microsoft/ethr.git
synced 2024-09-20 06:46:14 +08:00
Fix handling of interrupts (#125)
This commit is contained in:
parent
83c2ede294
commit
233968d71d
19
client.go
19
client.go
|
@ -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{})
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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.")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue