[NOD-869] Close panicHandlerDone instead of sending an empty struct + use time.After instead of time.Tick (#668)

This commit is contained in:
Svarog 2020-03-25 16:14:08 +02:00 committed by GitHub
parent bc6ce6ed53
commit 1020402b34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,10 +2,11 @@ package panics
import ( import (
"fmt" "fmt"
"github.com/kaspanet/kaspad/logs"
"os" "os"
"runtime/debug" "runtime/debug"
"time" "time"
"github.com/kaspanet/kaspad/logs"
) )
// HandlePanic recovers panics, log them, runs an optional panicHandler, // HandlePanic recovers panics, log them, runs an optional panicHandler,
@ -24,15 +25,16 @@ func HandlePanic(log *logs.Logger, goroutineStackTrace []byte) {
} }
log.Criticalf("Stack trace: %s", debug.Stack()) log.Criticalf("Stack trace: %s", debug.Stack())
log.Backend().Close() log.Backend().Close()
panicHandlerDone <- struct{}{} close(panicHandlerDone)
}() }()
const panicHandlerTimeout = 5 * time.Second const panicHandlerTimeout = 5 * time.Second
select { select {
case <-time.Tick(panicHandlerTimeout): case <-time.After(panicHandlerTimeout):
fmt.Fprintln(os.Stderr, "Couldn't handle a fatal error. Exiting...") fmt.Fprintln(os.Stderr, "Couldn't handle a fatal error. Exiting...")
case <-panicHandlerDone: case <-panicHandlerDone:
} }
log.Criticalf("Exiting")
os.Exit(1) os.Exit(1)
} }