From 393f80165c3bbeb1e5cef625811825140e6f5d90 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 19 Sep 2024 05:55:53 +0100 Subject: [PATCH] fix: add timeout to reading history from exchanger (#2920) --- .../core/history/changeset/ChangeExchangeCoordinator.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/ChangeExchangeCoordinator.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/ChangeExchangeCoordinator.java index 2f3398a60..3c020d422 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/ChangeExchangeCoordinator.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/ChangeExchangeCoordinator.java @@ -4,6 +4,8 @@ import com.sk89q.worldedit.history.change.Change; import org.jetbrains.annotations.ApiStatus; import java.util.concurrent.Exchanger; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.function.BiConsumer; /** @@ -32,8 +34,9 @@ public class ChangeExchangeCoordinator implements AutoCloseable { .start(() -> this.runnerTask.accept(this.exchanger, new Change[length])); } try { - return exchanger.exchange(consumed); - } catch (InterruptedException e) { + // Allow a reasonable timeout in case of weirdness + return exchanger.exchange(consumed, 30, TimeUnit.SECONDS); + } catch (InterruptedException | TimeoutException e) { this.runner.interrupt(); Thread.currentThread().interrupt(); return null;