From 7f3fd0af0892c24ab8c357a9cf17f5a4fce9d8ed Mon Sep 17 00:00:00 2001 From: woodser Date: Fri, 29 Dec 2023 11:17:27 -0500 Subject: [PATCH] finish open offer manager tasks before shut down --- .../haveno/core/offer/OpenOfferManager.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/haveno/core/offer/OpenOfferManager.java b/core/src/main/java/haveno/core/offer/OpenOfferManager.java index f14e40785d..ce3a86a28d 100644 --- a/core/src/main/java/haveno/core/offer/OpenOfferManager.java +++ b/core/src/main/java/haveno/core/offer/OpenOfferManager.java @@ -316,20 +316,22 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe int size = openOffers.size(); log.info("Remove open offers at shutDown. Number of open offers: {}", size); if (offerBookService.isBootstrapped() && size > 0) { - UserThread.execute(() -> { - openOffers.forEach(openOffer -> offerBookService.removeOfferAtShutDown(openOffer.getOffer().getOfferPayload())); + HavenoUtils.submitToThread(() -> { // finish tasks + UserThread.execute(() -> { + openOffers.forEach(openOffer -> offerBookService.removeOfferAtShutDown(openOffer.getOffer().getOfferPayload())); - // Force broadcaster to send out immediately, otherwise we could have a 2 sec delay until the - // bundled messages sent out. - broadcaster.flush(); + // Force broadcaster to send out immediately, otherwise we could have a 2 sec delay until the + // bundled messages sent out. + broadcaster.flush(); - if (completeHandler != null) { - // For typical number of offers we are tolerant with delay to give enough time to broadcast. - // If number of offers is very high we limit to 3 sec. to not delay other shutdown routines. - int delay = Math.min(3000, size * 200 + 500); - UserThread.runAfter(completeHandler, delay, TimeUnit.MILLISECONDS); - } - }); + if (completeHandler != null) { + // For typical number of offers we are tolerant with delay to give enough time to broadcast. + // If number of offers is very high we limit to 3 sec. to not delay other shutdown routines. + int delay = Math.min(3000, size * 200 + 500); + UserThread.runAfter(completeHandler, delay, TimeUnit.MILLISECONDS); + } + }); + }, THREAD_ID); } else { broadcaster.flush(); if (completeHandler != null)