illusivesoulworks / veinmining

Minecraft Mod: A lightweight, highly configurable Vein Mining enchantment for tools.
Other
30 stars 16 forks source link

[Bug]: Freeze on World load #46

Closed canitzp closed 2 years ago

canitzp commented 2 years ago

Minecraft Version

1.18.1

What happened?

I just wanted to load a new world.

I already have spotted the issue, cause like the log I attached at the bottom shows, it is a "ConcurrentModificationException" and I found this code snippet: https://github.com/TheIllusiveC4/VeinMining/blob/1.18.x/forge/src/main/java/top/theillusivec4/veinmining/veinmining/logic/BlockGroups.java#L47-L48 There you change the map, while iterating over it, which is not allowed and lead to random crashes, but only sometimes and under some vms never. The two possible fixes are:

  1. iterate of a copy of the map
  2. change the map type from HashMap to ConcurrentHashMap (or something like that), which can handle simultanious read and writes I would prefer Number 1.

How do you trigger this bug?

Load a new world.

Loader

Forge

Loader Version

39.0.75

Mod Version

1.18.1-0.16

Relevant Log Outputs

Error in log [09Feb2022 13:41:13.472] [Server thread/ERROR] [net.minecraftforge.fml.javafmlmod.FMLModContainer/]: Exception caught during firing event: null Index: 1 Listeners: 0: NORMAL 1: net.minecraftforge.eventbus.EventBus$$Lambda$4519/0x00000008018f2470@96a649f java.util.ConcurrentModificationException at java.base/java.util.HashMap.merge(HashMap.java:1385) at TRANSFORMER/veinmining@1.18.1-0.16/top.theillusivec4.veinmining.veinmining.logic.BlockGroups.init(BlockGroups.java:48) at TRANSFORMER/veinmining@1.18.1-0.16/top.theillusivec4.veinmining.veinmining.logic.BlockProcessor.rebuild(BlockProcessor.java:43) at TRANSFORMER/veinmining@1.18.1-0.16/top.theillusivec4.veinmining.VeinMiningMod.bakeConfigs(VeinMiningMod.java:98) at TRANSFORMER/veinmining@1.18.1-0.16/top.theillusivec4.veinmining.VeinMiningMod.configLoading(VeinMiningMod.java:82) at MC-BOOTSTRAP/eventbus@5.0.3/net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:247) at MC-BOOTSTRAP/eventbus@5.0.3/net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:239) at MC-BOOTSTRAP/eventbus@5.0.3/net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) at MC-BOOTSTRAP/eventbus@5.0.3/net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) at LAYER PLUGIN/javafmllanguage@1.18.1-39.0.75/net.minecraftforge.fml.javafmlmod.FMLModContainer.lambda$new$0(FMLModContainer.java:55) at LAYER PLUGIN/fmlcore@1.18.1-39.0.75/net.minecraftforge.fml.ModContainer.lambda$dispatchConfigEvent$7(ModContainer.java:149) at java.base/java.util.Optional.ifPresent(Optional.java:178) at LAYER PLUGIN/fmlcore@1.18.1-39.0.75/net.minecraftforge.fml.ModContainer.dispatchConfigEvent(ModContainer.java:149) at LAYER PLUGIN/fmlcore@1.18.1-39.0.75/net.minecraftforge.fml.config.ModConfig.fireEvent(ModConfig.java:90) at LAYER PLUGIN/fmlcore@1.18.1-39.0.75/net.minecraftforge.fml.config.ConfigTracker.openConfig(ConfigTracker.java:76) at LAYER PLUGIN/fmlcore@1.18.1-39.0.75/net.minecraftforge.fml.config.ConfigTracker.lambda$loadConfigs$1(ConfigTracker.java:64) at java.base/java.lang.Iterable.forEach(Iterable.java:75) at java.base/java.util.Collections$SynchronizedCollection.forEach(Collections.java:2131) at LAYER PLUGIN/fmlcore@1.18.1-39.0.75/net.minecraftforge.fml.config.ConfigTracker.loadConfigs(ConfigTracker.java:64) at TRANSFORMER/forge@39.0.75/net.minecraftforge.server.ServerLifecycleHooks.handleServerAboutToStart(ServerLifecycleHooks.java:94) at TRANSFORMER/minecraft@1.18.1/net.minecraft.client.server.IntegratedServer.m_7038_(IntegratedServer.java:65) at TRANSFORMER/minecraft@1.18.1/net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:644) at TRANSFORMER/minecraft@1.18.1/net.minecraft.server.MinecraftServer.m_177918_(MinecraftServer.java:258) at java.base/java.lang.Thread.run(Thread.java:833) [13:41:13] [Server thread/ERROR]: Encountered an unexpected exception java.util.ConcurrentModificationException: null at java.util.HashMap.merge(HashMap.java:1385) ~[?:?] at top.theillusivec4.veinmining.veinmining.logic.BlockGroups.init(BlockGroups.java:48) ~[veinmining-forge-1.18.1-0.16.jar%23279!/:task ':jar' property 'archiveVersion'] at top.theillusivec4.veinmining.veinmining.logic.BlockProcessor.rebuild(BlockProcessor.java:43) ~[veinmining-forge-1.18.1-0.16.jar%23279!/:task ':jar' property 'archiveVersion'] at top.theillusivec4.veinmining.VeinMiningMod.bakeConfigs(VeinMiningMod.java:98) ~[veinmining-forge-1.18.1-0.16.jar%23279!/:task ':jar' property 'archiveVersion'] at top.theillusivec4.veinmining.VeinMiningMod.configLoading(VeinMiningMod.java:82) ~[veinmining-forge-1.18.1-0.16.jar%23279!/:task ':jar' property 'archiveVersion'] at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:247) ~[eventbus-5.0.3.jar%2337!/:?] at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:239) ~[eventbus-5.0.3.jar%2337!/:?] at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) ~[eventbus-5.0.3.jar%2337!/:?] at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) ~[eventbus-5.0.3.jar%2337!/:?] at net.minecraftforge.fml.javafmlmod.FMLModContainer.lambda$new$0(FMLModContainer.java:55) ~[javafmllanguage-1.18.1-39.0.75.jar%23291!/:?] at net.minecraftforge.fml.ModContainer.lambda$dispatchConfigEvent$7(ModContainer.java:149) ~[fmlcore-1.18.1-39.0.75.jar%23290!/:?] at java.util.Optional.ifPresent(Optional.java:178) ~[?:?] at net.minecraftforge.fml.ModContainer.dispatchConfigEvent(ModContainer.java:149) ~[fmlcore-1.18.1-39.0.75.jar%23290!/:?] at net.minecraftforge.fml.config.ModConfig.fireEvent(ModConfig.java:90) ~[fmlcore-1.18.1-39.0.75.jar%23290!/:?] at net.minecraftforge.fml.config.ConfigTracker.openConfig(ConfigTracker.java:76) ~[fmlcore-1.18.1-39.0.75.jar%23290!/:?] at net.minecraftforge.fml.config.ConfigTracker.lambda$loadConfigs$1(ConfigTracker.java:64) ~[fmlcore-1.18.1-39.0.75.jar%23290!/:?] at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?] at java.util.Collections$SynchronizedCollection.forEach(Collections.java:2131) ~[?:?] at net.minecraftforge.fml.config.ConfigTracker.loadConfigs(ConfigTracker.java:64) ~[fmlcore-1.18.1-39.0.75.jar%23290!/:?] at net.minecraftforge.server.ServerLifecycleHooks.handleServerAboutToStart(ServerLifecycleHooks.java:94) ~[forge-1.18.1-39.0.75-universal.jar%23293!/:?] at net.minecraft.client.server.IntegratedServer.m_7038_(IntegratedServer.java:65) ~[client-1.18.1-20211210.034407-srg.jar%23289!/:?] at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:644) ~[client-1.18.1-20211210.034407-srg.jar%23289!/:?] at net.minecraft.server.MinecraftServer.m_177918_(MinecraftServer.java:258) ~[client-1.18.1-20211210.034407-srg.jar%23289!/:?] at java.lang.Thread.run(Thread.java:833) [?:?]
TheIllusiveC4 commented 2 years ago

Huh, that's weird. Certainly the error is pretty clear about its cause, which is what you've pointed out, so I'll work on a fix for that. However, I must be missing something obvious because I can't tell why the CME is occurring. I'm not iterating through the map at all, the only reference to the map is when calling the merge method. I'm iterating through an unrelated HashSet<String> created from createGroups.

TheIllusiveC4 commented 2 years ago

I think what's happening is that the config itself is being loaded from multiple threads, which causes the CME to occur. It's hard for me to verify since I cannot reproduce it reliably, but try out the new update and let me know how it goes.