Repository navigation
fix(profile-ex): 修复并发创建重复 ProfileExItem 的问题 - #10420
Merged
Merged
Conversation
ConcurrentBag only makes individual operations safe. GetProfileExItem performed FirstOrDefault and AddProfileEx as separate operations, so concurrent speed tests could both miss and create duplicate entries for the same IndexId. Recheck under a dedicated lock before creating, and replace the bag under the same lock in InitData/ClearAll so creation cannot target a bag that is being swapped. Existing reads and item updates stay lock-free.
patterniha
pushed a commit
to patterniha/PattN
that referenced
this pull request
Oct 20, 2026
Early merge of 2dust#10420 (PR head bddd538)
Contributor
|
For reference, I opened #10410 on October 18 to address the same |
3 tasks done
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.
问题
在
ProfileExManager.GetProfileExItem()中,当前逻辑是:虽然
_lstProfileEx使用的是ConcurrentBag,但“查找是否存在”与“创建新项”是两个独立操作,并不是原子的。当多个线程同时处理相同
IndexId时,可能出现多个线程同时判断该项不存在,随后分别调用AddProfileEx(),最终导致同一个IndexId出现多个ProfileExItem。这个问题会导致:
ProfileExManagerConcurrencyTests.SetTestDelay_ShouldCreateOneEntryPerIndex出现随机失败,例如:
该问题是在最近 WebAPI CI 增加 ServiceLib 回归测试后暴露出来的,但实际问题位于原有
ProfileExManager并发逻辑中,与 WebAPI 本身无关。修改
见文件
验证
Nozilla-X@ea25ff3