mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-02 19:22:08 +00:00
Pump native chunk tasks while server stop waits for pregen
On Paper only the server thread advances chunk tasks, so a stop that blocks on a running pregen can wait forever. Stop now polls the native chunk queue while joining the pregen worker, and pregen skips eviction and flush scheduling once the server is stopping.
Upstream: 083e68986
This commit is contained in:
1 parent
e87e6d9fae
commit
ae60b14402
8 files changed
+226
-3
No files matched your search
+12
@@ -1131,6 +1131,18 @@ public class NMSBinding implements INMSBinding {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pollChunkTask(World world) {
|
||||
if (J.isFolia()) {
|
||||
return false;
|
||||
}
|
||||
ServerLevel level = ((CraftWorld) world).getHandle();
|
||||
if (Thread.currentThread() != level.getServer().getRunningThread()) {
|
||||
throw new IllegalStateException("Native chunk tasks can only be polled from the server thread.");
|
||||
}
|
||||
return level.getChunkSource().pollTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flushChunkIO(World world) {
|
||||
try {
|
||||
|
||||
+11
@@ -18,6 +18,17 @@ public class NMSBindingShutdownBoundaryContractTest {
|
||||
assertTrue(boundary.contains("server.getRunningThread()"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void chunkTaskPollingIsServerThreadOnlyAndSkipsFolia() throws Exception {
|
||||
String source = Files.readString(Path.of(System.getProperty("iris.nmsBindingSource"))).replace("\r\n", "\n");
|
||||
String polling = section(source, "public boolean pollChunkTask", "public void flushChunkIO");
|
||||
|
||||
int foliaGuard = polling.indexOf("J.isFolia()");
|
||||
int ownerGuard = polling.indexOf("level.getServer().getRunningThread()");
|
||||
int poll = polling.indexOf("level.getChunkSource().pollTask()");
|
||||
assertTrue(foliaGuard >= 0 && ownerGuard > foliaGuard && poll > ownerGuard);
|
||||
}
|
||||
|
||||
private static String section(String source, String startMarker, String endMarker) {
|
||||
int start = source.indexOf(startMarker);
|
||||
int end = source.indexOf(endMarker, start);
|
||||
|
||||
@@ -993,7 +993,16 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
StudioBridges.closeAll();
|
||||
|
||||
try {
|
||||
PregeneratorJob.shutdownAndWait(SERVER_STOP_PREGEN_TIMEOUT_MILLIS);
|
||||
if (J.isFolia()) {
|
||||
PregeneratorJob.shutdownAndWait(SERVER_STOP_PREGEN_TIMEOUT_MILLIS);
|
||||
} else {
|
||||
List<World> worlds = Bukkit.getWorlds();
|
||||
PregeneratorJob.shutdownAndWait(SERVER_STOP_PREGEN_TIMEOUT_MILLIS, () -> {
|
||||
for (World world : worlds) {
|
||||
INMS.get().pollChunkTask(world);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError("Failed to quiesce the Iris pregenerator before server shutdown.", e);
|
||||
}
|
||||
|
||||
+4
-1
@@ -52,7 +52,10 @@ public class BukkitEngineLifecycleContractTest {
|
||||
String waitedShutdown = method(jobSource,
|
||||
"private static boolean shutdownAndWait(PregeneratorJob inst, long timeoutMs)");
|
||||
assertBefore(waitedShutdown, "inst.worker.interrupt()", "inst.worker.join(");
|
||||
assertTrue(waitedShutdown.contains("inst.worker.isAlive()"));
|
||||
assertBefore(waitedShutdown, "inst.worker.join(", "finishShutdown(inst, timeoutMs)");
|
||||
String finishedShutdown = method(jobSource,
|
||||
"private static boolean finishShutdown(PregeneratorJob inst, long timeoutMs)");
|
||||
assertBefore(finishedShutdown, "inst.worker.isAlive()", "instance.compareAndSet(inst, null)");
|
||||
|
||||
String hooksSource = Files.readString(Path.of(System.getProperty("iris.bukkitEnginePlatformHooksSource")));
|
||||
String hookShutdown = method(hooksSource, "public void shutdownPregenerator(Engine engine)");
|
||||
|
||||
Reference in new issue
Block a user