From 051ec0dd65b34549f6c0cac064abea1dc74c5420 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Mon, 15 May 2023 00:26:20 -0700 Subject: [PATCH] Fix concurrenct access to lookups field in RegistryOps The concurrent access occurs on the Netty IO threads when serializing packets. Thus, it seems it was an oversight of the implementator of this function as there are typically more than one Netty IO thread. Fixes https://github.com/PaperMC/Folia/issues/11 --- ...access-to-lookups-field-in-RegistryO.patch | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 patches/server/0026-Fix-concurrenct-access-to-lookups-field-in-RegistryO.patch diff --git a/patches/server/0026-Fix-concurrenct-access-to-lookups-field-in-RegistryO.patch b/patches/server/0026-Fix-concurrenct-access-to-lookups-field-in-RegistryO.patch new file mode 100644 index 0000000..df997c3 --- /dev/null +++ b/patches/server/0026-Fix-concurrenct-access-to-lookups-field-in-RegistryO.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Spottedleaf +Date: Mon, 15 May 2023 00:20:59 -0700 +Subject: [PATCH] Fix concurrenct access to lookups field in RegistryOps + +The concurrent access occurs on the Netty IO threads when +serializing packets. Thus, it seems it was an oversight of +the implementator of this function as there are typically +more than one Netty IO thread. + +Fixes https://github.com/PaperMC/Folia/issues/11 + +diff --git a/src/main/java/net/minecraft/resources/RegistryOps.java b/src/main/java/net/minecraft/resources/RegistryOps.java +index 7709eeac907c4895a264cec0a3d453aa8b194c18..4495802efec958095bcfd41487b30c3c799d7b36 100644 +--- a/src/main/java/net/minecraft/resources/RegistryOps.java ++++ b/src/main/java/net/minecraft/resources/RegistryOps.java +@@ -19,11 +19,11 @@ public class RegistryOps extends DelegatingOps { + + private static RegistryOps.RegistryInfoLookup memoizeLookup(final RegistryOps.RegistryInfoLookup registryInfoGetter) { + return new RegistryOps.RegistryInfoLookup() { +- private final Map>, Optional>> lookups = new HashMap<>(); ++ private final Map>, Optional>> lookups = new java.util.concurrent.ConcurrentHashMap<>(); // Folia - fix concurrent access to lookups field + + @Override + public Optional> lookup(ResourceKey> registryRef) { +- return this.lookups.computeIfAbsent(registryRef, registryInfoGetter::lookup); ++ return (Optional>)this.lookups.computeIfAbsent(registryRef, registryInfoGetter::lookup); // Folia - fix concurrent access to lookups field + } + }; + }