GregTechCEu Modern

GregTechCEu Modern

6M Downloads

ServerChunkProvider mixin looks dangerous

embeddedt opened this issue ยท 1 comments

commented

Mixin: https://github.com/GregTechCEu/GregTech-Modern/blob/1.20.1/src/main/java/com/gregtechceu/gtceu/core/mixins/ServerChunkProviderMixin.java

While writes to the mbdLastChunk(Pos) arrays are synchronized, reads are not. If one thread is mutating the cache in storeInCache, there is a possibility a second thread could read an updated value for mbdLastChunkPos but still read the old chunk from mbdLastChunk. This will probably result in some obscure failure later down the line.

Personally, I would suggest doing the caching at a higher level in whatever worker threads are being used, rather than modifying the game's chunk provider. You could use the Forge event to be notified when the chunk unloads and invalidate the cache. I think it would be much cleaner and less likely to cause issues.

commented

yes please, blame kila this is dark magic to me