mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-10-14 00:59:33 +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 (
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user