Fix race condition in CardEdition.getCardInSet()#9542
Conversation
|
i wonder if it would be better to have cardsInSetLookupMap = cardStream.collect(
toMultimap(
e -> e.name,
e -> e,
MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER).arrayListValues()::build)
)
);And getAllCardsInSet() can just return |
d7de4dd to
3454c22
Compare
Ok, I thought this lazy initialization was important but it seems, during card database initialization, every card iterates through every edition calling getCardInSet(). This means the lookup map gets initialized for all editions during startup anyway. Let's initialize it in the constructor then. Fixed in 3454c22 |
|
@tool4ever @tehdiplomat what do you think? |
|
@fediazgon Currently, it has 3 Constuctors:
The first one is the one used in the Reader for reading the Edition files: the second one isn't used external, but only by the third one the third one is used for
Each one with an empty card list → that means, the third constructor can be updated to remove that unused extra Param, and might remove the second constructor too. (i might try a smaller MR that can be merged faster) |
|
I think having this one as its own change allows us to link this PR in the future in case there are other race conditions lying around as a way of documenting what to do. If we add to many changes it can be easy to miss the point of what the problem and the fix were. Also, this is currently a big issue for anyone that is playing custom cube drafts since, when I tested it, it was failing 1/4 times. |
3454c22 to
f75d8c2
Compare
|
@Hanmac Let's merge yours and this one. We can also just merge this one since it includes both commits. We will just show as 2 contributors for the same (squashed) commit. |
* Fix race condition in CardEdition.getCardInSet()
The
getCardInSet()method uses lazy initialization forcardsInSetLookupMapwithout synchronization. WhenBoosterDraft.loadCustomDrafts()processes multiple draft files in parallel usingCompletableFuture.supplyAsync(), multiple threads can callgetCardInSet()on the sameCardEditioninstance simultaneously.This causes
TreeMapinternal structure corruption with errors like:The solution is to apply double-checked locking pattern.
Closes #9504.