mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Release the plugin instance and runtime statics on disable
A disabled Iris stayed reachable through statics and a re-enable in the same JVM answered from the previous boot's caches. Disable now releases the instance, services, capability singletons and host bindings, and reaching Iris afterwards fails with "Iris is disabled" instead of a NullPointerException.
Upstream: 6c6dba023
This commit is contained in:
1 parent
c77a9fb012
commit
128e90ea9b
10 files changed
+173
-13
No files matched your search
@@ -39,6 +39,7 @@ import art.arcane.iris.core.SettingsHotloadWatch;
|
||||
import art.arcane.iris.core.ServerConfigurator;
|
||||
import art.arcane.iris.core.datapack.DatapackIngestService;
|
||||
import art.arcane.iris.core.datapack.DatapackIngestService.StartupValidationOutcome;
|
||||
import art.arcane.iris.core.lifecycle.IrisRuntimeStatics;
|
||||
import art.arcane.iris.core.lifecycle.ManagedWorldLoader;
|
||||
import art.arcane.iris.core.lifecycle.MissingWorldStorageLog;
|
||||
import art.arcane.iris.core.lifecycle.PaperLibBootstrap;
|
||||
@@ -205,16 +206,23 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
private volatile Thread serverLifecycleThread;
|
||||
|
||||
public static VolmitSender getSender() {
|
||||
if (sender == null) {
|
||||
sender = new VolmitSender(Bukkit.getConsoleSender());
|
||||
sender.setTag(instance.getTag());
|
||||
VolmitSender current = sender;
|
||||
if (current == null) {
|
||||
Iris plugin = instance;
|
||||
current = new VolmitSender(Bukkit.getConsoleSender());
|
||||
current.setTag(plugin == null ? IrisSafeguard.mode().tag("") : plugin.getTag());
|
||||
sender = current;
|
||||
}
|
||||
return sender;
|
||||
return current;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T service(Class<T> c) {
|
||||
return (T) instance.services.get(c);
|
||||
Iris plugin = instance;
|
||||
if (plugin == null || plugin.services == null) {
|
||||
throw new IllegalStateException("Iris is disabled; " + c.getSimpleName() + " is unavailable");
|
||||
}
|
||||
return (T) plugin.services.get(c);
|
||||
}
|
||||
|
||||
public static void callEvent(Event e) {
|
||||
@@ -253,7 +261,11 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
}
|
||||
|
||||
public static File getTemp() {
|
||||
return instance.getDataFolder("cache", "temp");
|
||||
Iris plugin = instance;
|
||||
if (plugin == null) {
|
||||
throw new IllegalStateException("Iris is disabled; the temp folder is unavailable");
|
||||
}
|
||||
return plugin.getDataFolder("cache", "temp");
|
||||
}
|
||||
|
||||
public static void msg(String string) {
|
||||
@@ -522,11 +534,11 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
Iris::msg,
|
||||
Iris::reportError,
|
||||
(event) -> Iris.callEvent((org.bukkit.event.Event) event),
|
||||
() -> Iris.instance.getDataFolder(),
|
||||
(path) -> Iris.instance.getDataFile(path),
|
||||
() -> Iris.instance.getJarFile(),
|
||||
() -> Iris.instance.getIrisVersion(),
|
||||
() -> Iris.instance.getMCVersion()));
|
||||
this::getDataFolder,
|
||||
this::getDataFile,
|
||||
this::getJarFile,
|
||||
this::getIrisVersion,
|
||||
this::getMCVersion));
|
||||
SlimJar.load();
|
||||
}
|
||||
|
||||
@@ -951,10 +963,19 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
J.attempt(MultiBurst.burst::close);
|
||||
J.attempt(MultiBurst.ioBurst::close);
|
||||
clearQueues();
|
||||
IrisServices.clear();
|
||||
IrisRuntimeStatics.reset();
|
||||
releaseStatics();
|
||||
}
|
||||
}
|
||||
|
||||
private static void releaseStatics() {
|
||||
linkMultiverseCore = null;
|
||||
compat = null;
|
||||
tickets = null;
|
||||
sender = null;
|
||||
instance = null;
|
||||
}
|
||||
|
||||
private void quiesceRuntimeForServerShutdown(String reason) {
|
||||
serverStopTeardownDeferred.set(true);
|
||||
JigsawStudioService jigsawStudioService = IrisServices.getOrNull(JigsawStudioService.class);
|
||||
@@ -1067,6 +1088,7 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
Iris.reportError("Failed to run Iris post-shutdown cleanup.", e);
|
||||
} finally {
|
||||
IrisPlatforms.unbind();
|
||||
BukkitPlatform.releaseHost();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1248,7 +1270,7 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
}
|
||||
|
||||
public int getIrisVersion() {
|
||||
String input = Iris.instance.getDescription().getVersion();
|
||||
String input = getDescription().getVersion();
|
||||
int hyphenIndex = input.indexOf('-');
|
||||
if (hyphenIndex != -1) {
|
||||
String result = input.substring(0, hyphenIndex);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package art.arcane.iris;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
public class IrisDisabledStaticsTest {
|
||||
@Test
|
||||
public void serviceLookupAfterDisableStatesThatIrisIsDisabled() {
|
||||
assertNull(Iris.instance);
|
||||
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class, () -> Iris.service(Runnable.class));
|
||||
|
||||
assertEquals("Iris is disabled; Runnable is unavailable", failure.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tempFolderAfterDisableStatesThatIrisIsDisabled() {
|
||||
assertNull(Iris.instance);
|
||||
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class, Iris::getTemp);
|
||||
|
||||
assertEquals("Iris is disabled; the temp folder is unavailable", failure.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -158,6 +158,16 @@ public class ServerConfigurator {
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetLoadedDatapackRuntime() {
|
||||
synchronized (DATAPACK_INSTALL_LOCK) {
|
||||
loadedDatapackRuntimeReady = false;
|
||||
loadedDatapackCompilerInputFingerprint = "";
|
||||
loadedDatapackRegistryRequirements = Map.of();
|
||||
loadedDatapackRuntimeGeneration++;
|
||||
loadedDatapackRestartRequired = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static LoadedDatapackRuntimeInvalidation invalidateLoadedDatapackRuntime() {
|
||||
synchronized (DATAPACK_INSTALL_LOCK) {
|
||||
boolean wasReady = loadedDatapackRuntimeReady;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package art.arcane.iris.core.lifecycle;
|
||||
|
||||
import art.arcane.iris.core.ServerConfigurator;
|
||||
import art.arcane.iris.core.localization.IrisLanguage;
|
||||
import art.arcane.iris.core.runtime.WorldRuntimeControlService;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
|
||||
/**
|
||||
* Drops every process-wide cache core keeps about the running server, so a disable leaves nothing an
|
||||
* enable in the same JVM could answer from. The host bindings are not cleared here: core still logs
|
||||
* through them while the adapter finishes its own teardown.
|
||||
*/
|
||||
public final class IrisRuntimeStatics {
|
||||
private IrisRuntimeStatics() {
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
IrisServices.clear();
|
||||
WorldLifecycleService.reset();
|
||||
WorldRuntimeControlService.reset();
|
||||
ServerConfigurator.resetLoadedDatapackRuntime();
|
||||
IrisLanguage.shutdown();
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,12 @@ public final class WorldLifecycleService {
|
||||
this.worldBackendByKey = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
synchronized (WorldLifecycleService.class) {
|
||||
instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static WorldLifecycleService get() {
|
||||
WorldLifecycleService current = instance;
|
||||
if (current != null) {
|
||||
|
||||
@@ -78,6 +78,11 @@ public final class IrisLanguage {
|
||||
private IrisLanguage() {
|
||||
}
|
||||
|
||||
public static synchronized void shutdown() {
|
||||
dataFolder = null;
|
||||
PLAIN_MEMO.set(null);
|
||||
}
|
||||
|
||||
public static boolean initialize() {
|
||||
if (!IrisPlatforms.isBound()) {
|
||||
return false;
|
||||
|
||||
@@ -79,6 +79,12 @@ public final class WorldRuntimeControlService {
|
||||
+ ", " + backend.describeCapabilities();
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
synchronized (WorldRuntimeControlService.class) {
|
||||
instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static WorldRuntimeControlService get() {
|
||||
WorldRuntimeControlService current = instance;
|
||||
if (current != null) {
|
||||
|
||||
@@ -103,6 +103,14 @@ public final class BukkitPlatform implements IrisPlatform {
|
||||
PLUGIN = plugin;
|
||||
}
|
||||
|
||||
public static void releaseHost() {
|
||||
PLUGIN = null;
|
||||
HUD_BAR = null;
|
||||
HUD_LANES = null;
|
||||
CONSOLE = null;
|
||||
BRIDGE = null;
|
||||
}
|
||||
|
||||
public static Plugin plugin() {
|
||||
Plugin plugin = PLUGIN;
|
||||
if (plugin == null) {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package art.arcane.iris.core.lifecycle;
|
||||
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class IrisRuntimeStaticsTest {
|
||||
@After
|
||||
public void clearStatics() {
|
||||
IrisRuntimeStatics.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resetUnbindsEveryRegisteredService() {
|
||||
IrisServices.register(Runnable.class, (Runnable) () -> {
|
||||
});
|
||||
|
||||
IrisRuntimeStatics.reset();
|
||||
|
||||
assertNull(IrisServices.getOrNull(Runnable.class));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package art.arcane.iris.platform.bukkit;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class BukkitPlatformHostReleaseTest {
|
||||
@After
|
||||
public void clearHost() {
|
||||
BukkitPlatform.releaseHost();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void releasingTheHostDropsThePluginTheHudAndTheBridges() {
|
||||
BukkitPlatform.hostPlugin(mock(Plugin.class));
|
||||
BukkitPlatform.hostConsoleSender(() -> null);
|
||||
|
||||
BukkitPlatform.releaseHost();
|
||||
|
||||
assertFalse(BukkitPlatform.hasPlugin());
|
||||
assertFalse(BukkitPlatform.hasHud());
|
||||
assertThrows(IllegalStateException.class, BukkitPlatform::console);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user