Skip to content

Commit

Permalink
Set SharedState only when it has not been set yet
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshiyukiMineo authored Dec 28, 2024
1 parent 2271c50 commit d3a2319
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions v2/distributed_gobreaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,22 @@ func NewDistributedCircuitBreaker[T any](ctx context.Context, store SharedDataSt
CircuitBreaker: NewCircuitBreaker[T](settings),
store: store,
}
state := SharedState{
State: dcb.state,
Generation: dcb.generation,
Counts: dcb.counts,
Expiry: dcb.expiry,

state, err := dcb.getSharedState(ctx)

Check failure on line 48 in v2/distributed_gobreaker.go

View workflow job for this annotation

GitHub Actions / test (1.23.x, ubuntu-latest, ./v2)

ineffectual assignment to state (ineffassign)

Check failure on line 48 in v2/distributed_gobreaker.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, ubuntu-latest, ./v2)

ineffectual assignment to state (ineffassign)

Check failure on line 48 in v2/distributed_gobreaker.go

View workflow job for this annotation

GitHub Actions / test (1.23.x, ubuntu-latest, ./v2)

ineffectual assignment to state (ineffassign)
if err == ErrNoSharedState {
state = SharedState{
State: dcb.state,
Generation: dcb.generation,
Counts: dcb.counts,
Expiry: dcb.expiry,
}
err = dcb.setSharedState(ctx, state)
}
err := dcb.setSharedState(ctx, state)
return dcb, err
if err != nil {
return nil, err
}

return dcb, nil
}

func (dcb *DistributedCircuitBreaker[T]) sharedStateKey() string {
Expand Down

0 comments on commit d3a2319

Please sign in to comment.