Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] fromOpenToHalfOpen 如果状态出现回滚,那么stateChangedCounter会更新一条错误数据。 #560

Open
JZWen opened this issue Feb 23, 2024 · 0 comments

Comments

@JZWen
Copy link

JZWen commented Feb 23, 2024

`// fromOpenToHalfOpen updates circuit breaker state machine from open to half-open.
// Return true only if current goroutine successfully accomplished the transformation.
func (b *circuitBreakerBase) fromOpenToHalfOpen(ctx *base.EntryContext) bool {
if b.state.cas(Open, HalfOpen) {
for _, listener := range stateChangeListeners {
listener.OnTransformToHalfOpen(Open, *b.rule)
}

	entry := ctx.Entry()
	if entry == nil {
		logging.Error(errors.New("nil entry"), "Nil entry in circuitBreakerBase.fromOpenToHalfOpen()", "rule", b.rule)
	} else {
		// add hook for entry exit
		// if the current circuit breaker performs the probe through this entry, but the entry was blocked,
		// this hook will guarantee current circuit breaker state machine will rollback to Open from Half-Open
		entry.WhenExit(func(entry *base.SentinelEntry, ctx *base.EntryContext) error {
			if ctx.IsBlocked() && b.state.cas(HalfOpen, Open) {
				for _, listener := range stateChangeListeners {
					listener.OnTransformToOpen(HalfOpen, *b.rule, 1.0)
				}
			}
			return nil
		})
	}

	stateChangedCounter.Add(float64(1), b.BoundRule().Resource, "Open", "HalfOpen")
	return true
}
return false

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant