From 9e95c6b5b4b59292d67c05031c5abb2fcb7b023d Mon Sep 17 00:00:00 2001 From: crschnick Date: Tue, 7 May 2024 10:51:12 +0000 Subject: [PATCH] Fix storage not saving when exiting while saving --- .../java/io/xpipe/app/storage/StandardStorage.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/xpipe/app/storage/StandardStorage.java b/app/src/main/java/io/xpipe/app/storage/StandardStorage.java index b5477cdd..14033565 100644 --- a/app/src/main/java/io/xpipe/app/storage/StandardStorage.java +++ b/app/src/main/java/io/xpipe/app/storage/StandardStorage.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.Base64; import java.util.List; import java.util.UUID; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Stream; @@ -226,7 +227,18 @@ public class StandardStorage extends DataStorage { } public void save(boolean dispose) { - if (!busyIo.tryLock()) { + try { + // If another save operation is in progress, we have to wait on dispose + // Otherwise the application may quit and kill the daemon thread that is performing the other save operation + if (dispose && !busyIo.tryLock(1, TimeUnit.MINUTES)) { + return; + } + } catch (InterruptedException e) { + return; + } + + // We don't need to wait on normal saves though + if (!dispose && !busyIo.tryLock()) { return; }