Skip to content

Commit

Permalink
sealing pipeline: Catch panics
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k authored and LexLuthr committed Mar 12, 2024
1 parent 046abf6 commit a765446
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions storage/pipeline/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"os"
"reflect"
"runtime"
"time"

"golang.org/x/xerrors"
Expand Down Expand Up @@ -39,8 +40,27 @@ func (m *Sealing) Plan(events []statemachine.Event, user interface{}) (interface
return nil, processed, nil
}

return func(ctx statemachine.Context, si SectorInfo) error {
err := next(ctx, si)
return func(ctx statemachine.Context, si SectorInfo) (err error) {
// handle panics
defer func() {
if r := recover(); r != nil {
buf := make([]byte, 1<<16)
n := runtime.Stack(buf, false)
buf = buf[:n]

l := Log{
Timestamp: uint64(time.Now().Unix()),
Message: fmt.Sprintf("panic: %v\n%s", r, buf),
Kind: "panic",
}
si.logAppend(l)

err = fmt.Errorf("panic: %v\n%s", r, buf)
}
}()

// execute the next state
err = next(ctx, si)
if err != nil {
log.Errorf("unhandled sector error (%d): %+v", si.SectorNumber, err)
return nil
Expand Down

0 comments on commit a765446

Please sign in to comment.