fix: KeyPool 并发竞态 — 防止多请求同时命中同一 Key#25
Merged
Merged
Conversation
This was referenced Jul 15, 2026
bigmanBass666
marked this pull request as ready for review
July 16, 2026 17:50
bigmanBass666
pushed a commit
that referenced
this pull request
Jul 16, 2026
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.
问题
KeyPool.Next() 的 Allow() 是只读检查,不预留 key。两个并发请求可同时看到同一个 key Allow() == true,都拿到并发送请求,导致上游收到双倍请求 → 429。
修复
在 KeyPool 中新增 inUse []bool 字段:
效果
两个并发请求不会再同时拿到同一个 key。实测高峰期 17:00 的 429 率应有明显下降(之前单个 key 一分钟内被突刺 24 次的情况不再出现)。
后续