3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Handle exceptions relating to CompletableFuture operations

Solves #374
Dieser Commit ist enthalten in:
A248 2020-10-26 13:52:04 -04:00
Ursprung cfb9104696
Commit 278930a008
8 geänderte Dateien mit 91 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -425,8 +425,11 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
.toArray((IntFunction<CompletableFuture<Void>[]>) CompletableFuture[]::new)); .toArray((IntFunction<CompletableFuture<Void>[]>) CompletableFuture[]::new));
playersTeardownFuture.get(10, TimeUnit.SECONDS); playersTeardownFuture.get(10, TimeUnit.SECONDS);
} catch (TimeoutException | ExecutionException e) { } catch (TimeoutException e) {
timedOut = true; timedOut = true;
} catch (ExecutionException e) {
timedOut = true;
logger.error("Exception while tearing down player connections", e);
} }
eventManager.fireShutdownEvent(); eventManager.fireShutdownEvent();

Datei anzeigen

@ -149,7 +149,11 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
Unpooled.wrappedBuffer(copy)); Unpooled.wrappedBuffer(copy));
playerConnection.write(copied); playerConnection.write(copied);
} }
}, playerConnection.eventLoop()); }, playerConnection.eventLoop())
.exceptionally((ex) -> {
logger.error("Exception while handling plugin message {}", packet, ex);
return null;
});
return true; return true;
} }
@ -186,7 +190,11 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
server.getEventManager().fire( server.getEventManager().fire(
new PlayerAvailableCommandsEvent(serverConn.getPlayer(), rootNode)) new PlayerAvailableCommandsEvent(serverConn.getPlayer(), rootNode))
.thenAcceptAsync(event -> playerConnection.write(commands), playerConnection.eventLoop()); .thenAcceptAsync(event -> playerConnection.write(commands), playerConnection.eventLoop())
.exceptionally((ex) -> {
logger.error("Exception while handling available commands for {}", playerConnection, ex);
return null;
});
return true; return true;
} }

Datei anzeigen

@ -157,7 +157,11 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
smc.write(packet); smc.write(packet);
} }
} }
}, smc.eventLoop()); }, smc.eventLoop())
.exceptionally((ex) -> {
logger.error("Exception while handling player chat for {}", player, ex);
return null;
});
} }
return true; return true;
} }
@ -225,7 +229,12 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
Unpooled.wrappedBuffer(copy)); Unpooled.wrappedBuffer(copy));
backendConn.write(message); backendConn.write(message);
} }
}, backendConn.eventLoop()); }, backendConn.eventLoop())
.exceptionally((ex) -> {
logger.error("Exception while handling plugin message packet for {}",
player, ex);
return null;
});
} }
} }
} }
@ -423,7 +432,12 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
resp.getOffers().addAll(offers); resp.getOffers().addAll(offers);
player.getConnection().write(resp); player.getConnection().write(resp);
} }
}, player.getConnection().eventLoop()); }, player.getConnection().eventLoop())
.exceptionally((ex) -> {
logger.error("Exception while handling command tab completion for player {} executing {}",
player, command, ex);
return null;
});
return true; // Sorry, handler; we're just gonna have to lie to you here. return true; // Sorry, handler; we're just gonna have to lie to you here.
} }
@ -475,7 +489,13 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
player.getUsername(), player.getUsername(),
command, e); command, e);
} }
}, player.getConnection().eventLoop()); }, player.getConnection().eventLoop())
.exceptionally((ex) -> {
logger.error(
"Exception while finishing command tab completion, with request {} and response {}",
request, response, ex);
return null;
});
} }
private void finishRegularTabComplete(TabCompleteRequest request, TabCompleteResponse response) { private void finishRegularTabComplete(TabCompleteRequest request, TabCompleteResponse response) {
@ -490,7 +510,13 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
response.getOffers().add(new Offer(s)); response.getOffers().add(new Offer(s));
} }
player.getConnection().write(response); player.getConnection().write(response);
}, player.getConnection().eventLoop()); }, player.getConnection().eventLoop())
.exceptionally((ex) -> {
logger.error(
"Exception while finishing regular tab completion, with request {} and response{}",
request, response, ex);
return null;
});
} }
private CompletableFuture<Void> processCommandExecuteResult(String originalCommand, private CompletableFuture<Void> processCommandExecuteResult(String originalCommand,

Datei anzeigen

@ -757,7 +757,13 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
} }
DisconnectEvent event = new DisconnectEvent(this, status); DisconnectEvent event = new DisconnectEvent(this, status);
server.getEventManager().fire(event).thenRun(() -> this.teardownFuture.complete(null)); server.getEventManager().fire(event).whenComplete((val, ex) -> {
if (ex == null) {
this.teardownFuture.complete(null);
} else {
this.teardownFuture.completeExceptionally(ex);
}
});
} }
public CompletableFuture<Void> getTeardownFuture() { public CompletableFuture<Void> getTeardownFuture() {

Datei anzeigen

@ -183,7 +183,11 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
} else { } else {
initializePlayer(GameProfile.forOfflinePlayer(login.getUsername()), false); initializePlayer(GameProfile.forOfflinePlayer(login.getUsername()), false);
} }
}, mcConnection.eventLoop()); }, mcConnection.eventLoop())
.exceptionally((ex) -> {
logger.error("Exception in pre-login stage", ex);
return null;
});
} }
private EncryptionRequest generateEncryptionRequest() { private EncryptionRequest generateEncryptionRequest() {
@ -202,6 +206,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
server.getConfiguration().getPlayerInfoForwardingMode()); server.getConfiguration().getPlayerInfoForwardingMode());
GameProfileRequestEvent profileRequestEvent = new GameProfileRequestEvent(inbound, profile, GameProfileRequestEvent profileRequestEvent = new GameProfileRequestEvent(inbound, profile,
onlineMode); onlineMode);
final GameProfile finalProfile = profile;
server.getEventManager().fire(profileRequestEvent).thenCompose(profileEvent -> { server.getEventManager().fire(profileRequestEvent).thenCompose(profileEvent -> {
if (mcConnection.isClosed()) { if (mcConnection.isClosed()) {
@ -229,6 +234,9 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
completeLoginProtocolPhaseAndInitialize(player); completeLoginProtocolPhaseAndInitialize(player);
} }
}, mcConnection.eventLoop()); }, mcConnection.eventLoop());
}).exceptionally((ex) -> {
logger.error("Exception during connection of {}", finalProfile, ex);
return null;
}); });
} }
@ -274,7 +282,11 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
server.getEventManager().fire(new PostLoginEvent(player)) server.getEventManager().fire(new PostLoginEvent(player))
.thenRun(() -> connectToInitialServer(player)); .thenRun(() -> connectToInitialServer(player));
} }
}, mcConnection.eventLoop()); }, mcConnection.eventLoop())
.exceptionally((ex) -> {
logger.error("Exception while completing login initialisation phase for {}", player, ex);
return null;
});
} }
private void connectToInitialServer(ConnectedPlayer player) { private void connectToInitialServer(ConnectedPlayer player) {
@ -291,7 +303,11 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
return; return;
} }
player.createConnectionRequest(toTry.get()).fireAndForget(); player.createConnectionRequest(toTry.get()).fireAndForget();
}, mcConnection.eventLoop()); }, mcConnection.eventLoop())
.exceptionally((ex) -> {
logger.error("Exception while connecting {} to initial server", player, ex);
return null;
});
} }
@Override @Override

Datei anzeigen

@ -163,7 +163,11 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping))) .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping)))
.thenAcceptAsync(event -> connection.closeWith( .thenAcceptAsync(event -> connection.closeWith(
LegacyDisconnect.fromServerPing(event.getPing(), packet.getVersion())), LegacyDisconnect.fromServerPing(event.getPing(), packet.getVersion())),
connection.eventLoop()); connection.eventLoop())
.exceptionally((ex) -> {
logger.error("Exception while handling legacy ping {}", packet, ex);
return null;
});
return true; return true;
} }
@ -189,7 +193,11 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
.toJson(event.getPing(), json); .toJson(event.getPing(), json);
connection.write(new StatusResponse(json)); connection.write(new StatusResponse(json));
}, },
connection.eventLoop()); connection.eventLoop())
.exceptionally((ex) -> {
logger.error("Exception while handling status request {}", packet, ex);
return null;
});
return true; return true;
} }

Datei anzeigen

@ -115,12 +115,10 @@ public class VelocityEventManager implements EventManager {
return CompletableFuture.completedFuture(event); return CompletableFuture.completedFuture(event);
} }
CompletableFuture<E> eventFuture = new CompletableFuture<>(); return CompletableFuture.supplyAsync(() -> {
service.execute(() -> {
fireEvent(event); fireEvent(event);
eventFuture.complete(event); return event;
}); }, service);
return eventFuture;
} }
@Override @Override

Datei anzeigen

@ -29,6 +29,7 @@ import java.util.Optional;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
import org.apache.logging.log4j.LogManager;
public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket> { public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket> {
@ -162,7 +163,12 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
// Send the response // Send the response
DatagramPacket responsePacket = new DatagramPacket(queryResponse, msg.sender()); DatagramPacket responsePacket = new DatagramPacket(queryResponse, msg.sender());
ctx.writeAndFlush(responsePacket, ctx.voidPromise()); ctx.writeAndFlush(responsePacket, ctx.voidPromise());
}, ctx.channel().eventLoop()); }, ctx.channel().eventLoop())
.exceptionally((ex) -> {
LogManager.getLogger(getClass()).error(
"Exception while writing GS4 response for query from {}", senderAddress, ex);
return null;
});
break; break;
} }
default: default: