Repository navigation
fix(scheduling): release acquired slot when account hydration fails - #8631
Merged
Wei-Shaw merged 1 commit intoNov 10, 2026
Merged
Conversation
newSelectionResult is the only exit for acquired Anthropic/Gemini selections. When hydrateSelectedAccount failed, the already acquired Redis concurrency slot was dropped with the error because callers only receive ReleaseFunc through a successful result. Release it on the error path, matching the OpenAI path that already does this via newAcquiredSelectionResult. Without the fix the slot stays occupied until its TTL expires, so the account can look idle while requests queue or fail.
Contributor
|
All contributors have signed the CLA. ✅ |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
问题
newSelectionResult是 Anthropic/Gemini 选号成功后的唯一出口。它在hydrateSelectedAccount失败时直接返回错误:但调用方在此之前已经通过
tryAcquireAccountSlot从 Redis 占用了并发槽位,而且只能从成功结果里拿到ReleaseFunc。所以这里返回错误时,槽位不会释放,只能等 TTL(默认 15 分钟)回收。触发条件
schedulerSnapshot.GetAccount失败(Redis 抖动/超时),或者账号在选号后被删除,返回 nil。newSelectionResult返回错误,result.ReleaseFunc被丢弃。结果:这个账号在最多 15 分钟内并发上限少 1。如果 hydrate 持续失败,账号会被逐步占满,表现为“账号明明空闲,但请求一直排队或 503”。
OpenAI 侧已经有对应处理(
newAcquiredSelectionResult在出错时调用release()),Anthropic/Gemini 侧漏了这一步。修复
hydrateSelectedAccount失败时,如果release != nil就先释放槽位,再返回错误。测试
新增
gateway_scheduling_slot_release_test.go:ReleaseFunc正常交给调用方。本地验证:
go test -tags=unit ./internal/service/通过go build ./...通过Closes #8632