From 26153def87b33a070690e68bcb90e82013cdea29 Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Wed, 3 Oct 2018 19:07:08 +0100 Subject: [PATCH] Fix FileIOThread concurrency issues (fixes #1505) FileIOThread was using two volatile counters in order to track if any pending work was in the queue, this causes potential concurrency issues when this counter is updated from multiple threads, potentially causing these counters to desync due to the unsafe volatile update --- ...-Fix-FileIOThread-concurrency-issues.patch | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Spigot-Server-Patches/0386-Fix-FileIOThread-concurrency-issues.patch diff --git a/Spigot-Server-Patches/0386-Fix-FileIOThread-concurrency-issues.patch b/Spigot-Server-Patches/0386-Fix-FileIOThread-concurrency-issues.patch new file mode 100644 index 0000000000..f122647c3b --- /dev/null +++ b/Spigot-Server-Patches/0386-Fix-FileIOThread-concurrency-issues.patch @@ -0,0 +1,35 @@ +From c829c08588842173ed4ce8d43a61f25e2a6a848c Mon Sep 17 00:00:00 2001 +From: Shane Freeder +Date: Wed, 3 Oct 2018 19:04:53 +0100 +Subject: [PATCH] Fix FileIOThread concurrency issues + +FileIOThread was using two volatile counters in order to track if +any pending work was in the queue, this causes potential concurrency +issues when this counter is updated from multiple threads, potentially +causing these counters to desync due to the unsafe volatile update + +diff --git a/src/main/java/net/minecraft/server/FileIOThread.java b/src/main/java/net/minecraft/server/FileIOThread.java +index 97917551..1959bc06 100644 +--- a/src/main/java/net/minecraft/server/FileIOThread.java ++++ b/src/main/java/net/minecraft/server/FileIOThread.java +@@ -9,7 +9,7 @@ import org.apache.logging.log4j.Logger; + public class FileIOThread implements Runnable { + private static final Logger a = LogManager.getLogger(); + private static final FileIOThread b = new FileIOThread(); +- private final List c = Collections.synchronizedList(Lists.newArrayList()); ++ private final List c = Collections.synchronizedList(Lists.newArrayList()); private List getThreadedIOQueue() { return c; } // Paper - OBFHELPER + private volatile long d; + private volatile long e; + private volatile boolean f; +@@ -72,7 +72,7 @@ public class FileIOThread implements Runnable { + public void b() throws InterruptedException { + this.f = true; + +- while(this.d != this.e) { ++ while(!this.getThreadedIOQueue().isEmpty()) { // Paper - check actual list size + Thread.sleep(10L); + } + +-- +2.19.0 +