mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-10-13 16:49:24 +00:00
[NOD-869] Close panicHandlerDone instead of sending an empty struct + use time.After instead of time.Tick (#668)
This commit is contained in:
parent
bc6ce6ed53
commit
1020402b34
@ -2,10 +2,11 @@ package panics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/kaspanet/kaspad/logs"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
|
||||
"github.com/kaspanet/kaspad/logs"
|
||||
)
|
||||
|
||||
// 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.Backend().Close()
|
||||
panicHandlerDone <- struct{}{}
|
||||
close(panicHandlerDone)
|
||||
}()
|
||||
|
||||
const panicHandlerTimeout = 5 * time.Second
|
||||
select {
|
||||
case <-time.Tick(panicHandlerTimeout):
|
||||
case <-time.After(panicHandlerTimeout):
|
||||
fmt.Fprintln(os.Stderr, "Couldn't handle a fatal error. Exiting...")
|
||||
case <-panicHandlerDone:
|
||||
}
|
||||
log.Criticalf("Exiting")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user