Fix race-condition-induced dead lock on replay restart in 1.14+

MC clears it scheduled tasks on disconnect. If we don't wait for
that to have happened on the async sender, then we might loose
some of the initial handshake packets (resulting in a dead lock in
fabric's registry syncing code).
This commit is contained in:
Jonas Herzig
2019-06-21 22:06:04 +02:00
parent 25ec311c86
commit 4213d37c76
2 changed files with 40 additions and 19 deletions

View File

@@ -35,6 +35,8 @@ import net.minecraft.network.ClientConnection;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
//#if MC>=11300
import com.replaymod.replay.mixin.EntityLivingBaseAccessor;
@@ -162,18 +164,22 @@ public class ReplayHandler {
channel.close();
// Force re-creation of camera entity by unloading the previous world
ReplayMod.instance.runSync(() -> {
//#if MC>=11300
mc.mouse.unlockCursor();
//#else
//$$ mc.setIngameNotInFocus();
//#endif
//#if MC>=11400
mc.disconnect();
//#else
//$$ mc.loadWorld(null);
//#endif
});
try {
ReplayMod.instance.runSync(() -> {
//#if MC>=11300
mc.mouse.unlockCursor();
//#else
//$$ mc.setIngameNotInFocus();
//#endif
//#if MC>=11400
mc.disconnect();
//#else
//$$ mc.loadWorld(null);
//#endif
});
} catch (InterruptedException | ExecutionException | TimeoutException e) {
LOGGER.error("Failed to properly restart (shutdown) replay:", e);
}
restrictions = new Restrictions();