Skip to content

Commit

Permalink
Merge pull request #388 from jhkimqd/jihwan/return-monitor-err
Browse files Browse the repository at this point in the history
fix: return error instead of infinitely hanging monitor
  • Loading branch information
jhkimqd authored Oct 7, 2024
2 parents 63d2c1d + f76a7a2 commit f794ec8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cmd/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ func monitor(ctx context.Context) error {
for {
err = fetchCurrentBlockData(ctx, ec, ms, isUiRendered)
if err != nil {
continue
log.Error().Msg(fmt.Sprintf("Error: %v", err))
// Send the error to the errChan channel to return.
errChan <- err
return
}
if ms.TopDisplayedBlock == nil || ms.SelectedBlock == nil {
ms.TopDisplayedBlock = ms.HeadBlock
Expand All @@ -184,6 +187,15 @@ func monitor(ctx context.Context) error {
}
}()

// Give time for the UI to attempt rendering.
time.Sleep(5 * time.Second)
if !isUiRendered {
// If UI cannot be rendered and returns, close the goroutine.
ctx.Done()
}
// Give time for goroutine to finish.
time.Sleep(1 * time.Second)
// Receive the errors from errChan and return to exit.
err = <-errChan
return err
}
Expand Down

0 comments on commit f794ec8

Please sign in to comment.