Skip to content

Commit

Permalink
Cancel erosion futures when closing session
Browse files Browse the repository at this point in the history
  • Loading branch information
AJ-Ferguson committed Sep 7, 2024
1 parent 34f5d71 commit 61a9c6b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/

package org.geysermc.geyser.erosion;

import java.io.Serial;
import java.util.concurrent.CancellationException;

public class ErosionCancellationException extends CancellationException {
@Serial
private static final long serialVersionUID = 1L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ public void sendPacket(BackendboundPacket packet) {

public void close() {
this.packetSender.close();

if (pendingLookup != null) {
pendingLookup.completeExceptionally(new ErosionCancellationException());
}
if (pendingBatchLookup != null) {
pendingBatchLookup.completeExceptionally(new ErosionCancellationException());
}
if (pickBlockLookup != null) {
pickBlockLookup.completeExceptionally(new ErosionCancellationException());
}
asyncPendingLookups.forEach(($, future) -> future.completeExceptionally(new ErosionCancellationException()));
}

public int getNextTransactionId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level.ClientboundLightUpdatePacket;
import io.netty.channel.EventLoop;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.erosion.ErosionCancellationException;
import org.geysermc.geyser.registry.loader.RegistryLoaders;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.GeyserLocale;
Expand Down Expand Up @@ -87,6 +88,8 @@ private <P extends T> void translate0(GeyserSession session, PacketTranslator<P>

try {
translator.translate(session, packet);
} catch (ErosionCancellationException ex) {
GeyserImpl.getInstance().getLogger().debug("Caught ErosionCancellationException");
} catch (Throwable ex) {
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.network.translator.packet.failed", packet.getClass().getSimpleName()), ex);
ex.printStackTrace();
Expand Down

0 comments on commit 61a9c6b

Please sign in to comment.