修复半开探测许可泄漏导致故障转移后无法切回 - #399
Open
wplct wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
自动故障转移的高优先级供应商熔断后,会在冷却期结束时进入 HalfOpen 并尝试恢复探测。旧实现通过计数器占用唯一的 HalfOpen 探测许可;如果请求在记录成功或失败之前被取消、提前返回或 panic,许可不会归还。
之后所有请求都无法再次探测已恢复的高优先级供应商,只能持续使用 fallback,看起来就是“故障转移后永远不会切回”。
修复
ProviderRequestPermit生命周期守卫持有 HalfOpen 探测许可。Drop时自动释放许可,覆盖正常返回、错误、任务取消和 panic 展开。测试
行为说明
当前恢复是请求驱动的:冷却期结束后的下一次业务请求触发 HalfOpen 探测,不新增后台健康检查任务。
Problem
After a higher-priority provider trips its circuit breaker, it enters HalfOpen after the cooldown period and should be probed again. The previous implementation reserved the single HalfOpen probe slot with a counter. If the request was cancelled, returned early, or panicked before recording success or failure, the slot was never released.
All later requests were then unable to probe the recovered provider and kept using the fallback indefinitely.
Fix
ProviderRequestPermitguard for HalfOpen probes.Drop, covering successful returns, errors, task cancellation, and panic unwinding.Tests
Behavioral note
Recovery remains request-driven: the first business request after cooldown triggers the HalfOpen probe. This PR does not introduce a background health-check task.