From ae4e4397e3682d0eddb7f44fcf8ed3aa1918750a Mon Sep 17 00:00:00 2001 From: Redned Date: Sun, 18 Jul 2021 17:04:16 -0500 Subject: [PATCH] Use a CompleteableFuture rather than constructing a new thread for logins --- .../network/session/GeyserSession.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 23f36b5f8..0daf15b60 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -560,8 +560,10 @@ public class GeyserSession implements CommandSender { } loggingIn = true; - // new thread so clients don't timeout - new Thread(() -> { + + // Use a future to prevent timeouts as all the authentication is handled sync + // This will be changed with the new protocol library. + CompletableFuture.supplyAsync(() -> { try { if (password != null && !password.isEmpty()) { AuthenticationService authenticationService; @@ -587,15 +589,14 @@ public class GeyserSession implements CommandSender { protocol = new MinecraftProtocol(validUsername); } - - connectDownstream(); } catch (InvalidCredentialsException | IllegalArgumentException e) { connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.auth.login.invalid", username)); disconnect(LanguageUtils.getPlayerLocaleString("geyser.auth.login.invalid.kick", getClientData().getLanguageCode())); } catch (RequestException ex) { ex.printStackTrace(); } - }).start(); + return null; + }).whenComplete((aVoid, ex) -> connectDownstream()); } /** @@ -608,8 +609,10 @@ public class GeyserSession implements CommandSender { } loggingIn = true; - // new thread so clients don't timeout - new Thread(() -> { + + // Use a future to prevent timeouts as all the authentication is handled sync + // This will be changed with the new protocol library. + CompletableFuture.supplyAsync(() -> { try { MsaAuthenticationService msaAuthenticationService = new MsaAuthenticationService(GeyserConnector.OAUTH_CLIENT_ID); @@ -629,7 +632,8 @@ public class GeyserSession implements CommandSender { } catch (RequestException ex) { ex.printStackTrace(); } - }).start(); + return null; + }).whenComplete((aVoid, ex) -> connectDownstream()); } /**