aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0868-Fix-concurrenct-access-to-lookups-field-in-RegistryO.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/server/0868-Fix-concurrenct-access-to-lookups-field-in-RegistryO.patch')
-rw-r--r--patches/server/0868-Fix-concurrenct-access-to-lookups-field-in-RegistryO.patch33
1 files changed, 33 insertions, 0 deletions
diff --git a/patches/server/0868-Fix-concurrenct-access-to-lookups-field-in-RegistryO.patch b/patches/server/0868-Fix-concurrenct-access-to-lookups-field-in-RegistryO.patch
new file mode 100644
index 0000000000..01fcd2b852
--- /dev/null
+++ b/patches/server/0868-Fix-concurrenct-access-to-lookups-field-in-RegistryO.patch
@@ -0,0 +1,33 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Spottedleaf <[email protected]>
+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..c7cfc3ca58f9439142fe5828117f6d576d7df10e 100644
+--- a/src/main/java/net/minecraft/resources/RegistryOps.java
++++ b/src/main/java/net/minecraft/resources/RegistryOps.java
+@@ -19,11 +19,14 @@ public class RegistryOps<T> extends DelegatingOps<T> {
+
+ private static RegistryOps.RegistryInfoLookup memoizeLookup(final RegistryOps.RegistryInfoLookup registryInfoGetter) {
+ return new RegistryOps.RegistryInfoLookup() {
+- private final Map<ResourceKey<? extends Registry<?>>, Optional<? extends RegistryOps.RegistryInfo<?>>> lookups = new HashMap<>();
++ // 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.
++ private final Map<ResourceKey<? extends Registry<?>>, Optional<? extends RegistryOps.RegistryInfo<?>>> lookups = new java.util.concurrent.ConcurrentHashMap<>(); // Paper - fix concurrent access to lookups field
+
+ @Override
+ public <T> Optional<RegistryOps.RegistryInfo<T>> lookup(ResourceKey<? extends Registry<? extends T>> registryRef) {
+- return this.lookups.computeIfAbsent(registryRef, registryInfoGetter::lookup);
++ return (Optional<RegistryOps.RegistryInfo<T>>)this.lookups.computeIfAbsent(registryRef, registryInfoGetter::lookup); // Paper - fix concurrent access to lookups field
+ }
+ };
+ }