-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Poll future for server shutdown instead of blocking on it
Should work around race condition where server exits before processing future
- Loading branch information
Showing
1 changed file
with
28 additions
and
4 deletions.
There are no files selected for viewing
32 changes: 28 additions & 4 deletions
32
src/main/java/org/embeddedt/vintagefix/mixin/bugfix/exit_freeze/IntegratedServerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,43 @@ | ||
package org.embeddedt.vintagefix.mixin.bugfix.exit_freeze; | ||
|
||
import com.mojang.authlib.GameProfileRepository; | ||
import com.mojang.authlib.minecraft.MinecraftSessionService; | ||
import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.integrated.IntegratedServer; | ||
import net.minecraft.server.management.PlayerProfileCache; | ||
import net.minecraft.util.datafix.DataFixer; | ||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper; | ||
import org.embeddedt.vintagefix.VintageFix; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import java.io.File; | ||
import java.net.Proxy; | ||
import java.util.concurrent.*; | ||
|
||
@Mixin(IntegratedServer.class) | ||
public class IntegratedServerMixin { | ||
public abstract class IntegratedServerMixin extends MinecraftServer { | ||
public IntegratedServerMixin(File anvilFileIn, Proxy proxyIn, DataFixer dataFixerIn, YggdrasilAuthenticationService authServiceIn, MinecraftSessionService sessionServiceIn, GameProfileRepository profileRepoIn, PlayerProfileCache profileCacheIn) { | ||
super(anvilFileIn, proxyIn, dataFixerIn, authServiceIn, sessionServiceIn, profileRepoIn, profileCacheIn); | ||
} | ||
|
||
/** | ||
* Sometimes the server thread is already gone at this point, try to prevent a freeze. | ||
*/ | ||
@Redirect(method = "initiateShutdown", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/integrated/IntegratedServer;isServerRunning()Z"), require = 0) | ||
private boolean checkThreadStatus(IntegratedServer instance) { | ||
return instance.isServerRunning() && ((Thread)ObfuscationReflectionHelper.getPrivateValue(MinecraftServer.class, instance, "field_175590_aa")).isAlive(); | ||
@Redirect(method = "initiateShutdown", at = @At(value = "INVOKE", target = "Lcom/google/common/util/concurrent/Futures;getUnchecked(Ljava/util/concurrent/Future;)Ljava/lang/Object;"), require = 0) | ||
private <V> V checkThreadStatus(Future<V> future) { | ||
while(this.isServerRunning() && ((Thread)ObfuscationReflectionHelper.getPrivateValue(MinecraftServer.class, this, "field_175590_aa")).isAlive()) { | ||
try { | ||
return future.get(500, TimeUnit.MILLISECONDS); | ||
} catch(InterruptedException e) { | ||
break; | ||
} catch(ExecutionException | CancellationException e) { | ||
throw new RuntimeException(e); | ||
} catch(TimeoutException ignored) {} | ||
} | ||
VintageFix.LOGGER.warn("Server thread has already exited, skipping logout process"); | ||
return null; | ||
} | ||
} |