Skip to content

Commit

Permalink
defer to recover to handle any panic in goroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
gatsbyz committed Dec 11, 2023
1 parent 279607f commit cd8c475
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ func monitor(ctx context.Context) error {
isUiRendered := false
errChan := make(chan error)
go func() {
defer func() {
if r := recover(); r != nil {
log.Error().Msg(fmt.Sprintf("Recovered in f: %v", r))
}
}()
select {
case <-ctx.Done(): // listens for a cancellation signal
return // exit the goroutine when the context is done
Expand Down

0 comments on commit cd8c475

Please sign in to comment.