Reduce scope for filter removal failure when getting actor events
Use a fresh context to remove the temporary filter installed solely to get the actor events. This should reduce chances of failure in a case where the original context may be expired/cancelled. Refactor removal into a `defer` statement for a more readable, concise return statement.
This commit is contained in:
parent
92ce665e5c
commit
4c868daf4e
@ -103,7 +103,6 @@ func (a *ActorEventHandler) GetActorEvents(ctx context.Context, evtFilter *types
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Install a filter just for this call, collect events, remove the filter
|
// Install a filter just for this call, collect events, remove the filter
|
||||||
|
|
||||||
tipSetCid, err := params.GetTipSetCid()
|
tipSetCid, err := params.GetTipSetCid()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get tipset cid: %w", err)
|
return nil, fmt.Errorf("failed to get tipset cid: %w", err)
|
||||||
@ -112,12 +111,13 @@ func (a *ActorEventHandler) GetActorEvents(ctx context.Context, evtFilter *types
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
evs := getCollected(ctx, f)
|
// Remove the temporary filter regardless of the original context.
|
||||||
if err := a.eventFilterManager.Remove(ctx, f.ID()); err != nil {
|
if err := a.eventFilterManager.Remove(context.Background(), f.ID()); err != nil {
|
||||||
log.Warnf("failed to remove filter: %s", err)
|
log.Warnf("failed to remove filter: %s", err)
|
||||||
}
|
}
|
||||||
return evs, nil
|
}()
|
||||||
|
return getCollected(ctx, f), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type filterParams struct {
|
type filterParams struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user