3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 12:30:06 +01:00
Paper/patches/server/0941-Fix-concurrenct-access-to-lookups-field-in-RegistryO.patch
2023-09-22 15:33:14 -07:00

31 Zeilen
1.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
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..29182c49b30110809f786ae99b47fcc67976562f 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<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<>();
+ 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
}
};
}