From 14804a00e0fe1d105ec8d3b84c83856976780245 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 11 Oct 2023 18:50:25 +0100 Subject: [PATCH] remove possibility for race condition --- .../src/main/java/com/sk89q/worldedit/LocalSession.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java index 62eb450506..ae62a4f73b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -406,12 +406,16 @@ public void setTimezone(ZoneId timezone) { */ public void clearHistory() { //FAWE start - if (Fawe.isMainThread() && historyWriteLock.isLocked()) { + if (Fawe.isMainThread() && !historyWriteLock.tryLock()) { // Do not make main thread wait if we cannot immediately clear history (on player logout usually) TaskManager.taskManager().async(this::clearHistoryTask); return; } - clearHistoryTask(); + try { + clearHistoryTask(); + } finally { + historyWriteLock.unlock(); + } } private void clearHistoryTask() {