NeoForge
NeoForge copied to clipboard
ModConfigEvent can cause concurrency issues in mods
Forge fires ModConfigEvent.Loading
when a config is first loaded, and ModConfigEvent.Reloading
when a config reloads as a result of the file watcher detecting a change. However, there is no locking done in the function that posts these events, meaning that it is possible for both Loading
and Reloading
to fire simultaneously.
Many mods have ModConfigEvent
event handlers that are not protected against this, and will therefore occasionally throw CMEs. This is technically a bug in those mods but I also think the design of this event is confusing/misleading - it really does not make sense for a config to load and reload at the exact same time.
https://github.com/ExcessiveAmountsOfZombies/Croptopia/issues/517 is an example of this occuring in the wild; I patched it in ModernFix by wrapping the Forge function that posts the event with a wrapper that synchronizes on the underlying config object, ensuring that all mods will never see two config events posted concurrently.