From 7f15b8e028fe2202954f3bf7e666c81d58716b9b Mon Sep 17 00:00:00 2001 From: frrist Date: Thu, 19 Jan 2023 09:40:38 -0800 Subject: [PATCH 1/2] fix: recover from panics in LoadSectorStates - related to https://github.com/filecoin-project/lotus/issues/10050 --- tasks/actorstate/miner/sector_events.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tasks/actorstate/miner/sector_events.go b/tasks/actorstate/miner/sector_events.go index 28ab6fdef..6020fd9b1 100644 --- a/tasks/actorstate/miner/sector_events.go +++ b/tasks/actorstate/miner/sector_events.go @@ -288,7 +288,12 @@ type SectorStates struct { // LoadSectorState loads all sectors from a miners partitions and returns a SectorStates structure containing individual // bitfields for all active, live, faulty and recovering sector. -func LoadSectorState(ctx context.Context, state miner.State) (*SectorStates, error) { +func LoadSectorState(ctx context.Context, state miner.State) (sectorStates *SectorStates, err error) { + defer func() { + if r := recover(); r != nil { + err = fmt.Errorf("LoadSectorState panic: %s", r) + } + }() _, span := otel.Tracer("").Start(ctx, "LoadSectorState") defer span.End() @@ -329,8 +334,6 @@ func LoadSectorState(ctx context.Context, state miner.State) (*SectorStates, err }); err != nil { return nil, err } - var err error - sectorStates := &SectorStates{} if sectorStates.Active, err = bitfield.MultiMerge(activeSectors...); err != nil { return nil, err } @@ -375,14 +378,14 @@ func DiffMinerSectorStates(ctx context.Context, extState extraction.State) (*Sec grp.Go(func() error { previous, err = LoadSectorState(grpCtx, extState.ParentState()) if err != nil { - return fmt.Errorf("loading previous sector states %w", err) + return fmt.Errorf("loading previous sector states for miner %s.(%s) with change type %s at height %d: %w", extState.Address(), extState.Actor().Code, extState.ChangeType(), extState.CurrentTipSet().Height(), err) } return nil }) grp.Go(func() error { current, err = LoadSectorState(grpCtx, extState.CurrentState()) if err != nil { - return fmt.Errorf("loading current sector states %w", err) + return fmt.Errorf("loading current sector states for miner %s.(%s) with change type %s at height %d: %w", extState.Address(), extState.Actor().Code, extState.ChangeType(), extState.CurrentTipSet().Height(), err) } return nil }) From 2d6b0734f41948691c20f090f15749e52df7da69 Mon Sep 17 00:00:00 2001 From: frrist Date: Tue, 24 Jan 2023 11:31:00 -0800 Subject: [PATCH 2/2] fix: initalize SectorStates structure - prevents panic --- tasks/actorstate/miner/sector_events.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tasks/actorstate/miner/sector_events.go b/tasks/actorstate/miner/sector_events.go index 6020fd9b1..88b9e6368 100644 --- a/tasks/actorstate/miner/sector_events.go +++ b/tasks/actorstate/miner/sector_events.go @@ -301,6 +301,7 @@ func LoadSectorState(ctx context.Context, state miner.State) (sectorStates *Sect liveSectors := []bitfield.BitField{} faultySectors := []bitfield.BitField{} recoveringSectors := []bitfield.BitField{} + sectorStates = &SectorStates{} // iterate the sector states if err := state.ForEachDeadline(func(_ uint64, dl miner.Deadline) error {