From e3353b29160eeea1ad7856d6e15c65529070ca14 Mon Sep 17 00:00:00 2001
From: Greg DiCristofaro <gregd@basistech.com>
Date: Thu, 27 Jul 2023 18:32:32 -0400
Subject: [PATCH] fixes for cancellation

---
 .../malwarescan/MalwareScanIngestModule.java       | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/Core/src/com/basistech/df/cybertriage/autopsy/malwarescan/MalwareScanIngestModule.java b/Core/src/com/basistech/df/cybertriage/autopsy/malwarescan/MalwareScanIngestModule.java
index 5cbbbed372..f528feb653 100644
--- a/Core/src/com/basistech/df/cybertriage/autopsy/malwarescan/MalwareScanIngestModule.java
+++ b/Core/src/com/basistech/df/cybertriage/autopsy/malwarescan/MalwareScanIngestModule.java
@@ -639,10 +639,8 @@ private boolean uploadFile(IngestJobState ingestJobState, String md5, long objId
         }
 
         /**
-         *
-         * @param ingestJobState
-         * @param md5objIdMapping
-         * @return
+         * Does long polling for any pending results.
+         * @param ingestJobState The state of the ingest job.
          * @throws InterruptedException
          * @throws CTCloudException
          * @throws org.sleuthkit.datamodel.Blackboard.BlackboardException
@@ -696,7 +694,13 @@ private void longPollForNotFound(IngestJobState ingestJobState) throws Interrupt
                 }
 
                 // exponential backoff before trying again
-                Thread.sleep(FILE_UPLOAD_RETRY_SLEEP_MILLIS * ((long) Math.pow(2, retry)));
+                long waitMultiplier = ((long) Math.pow(2, retry));
+                for (int i = 0; i < waitMultiplier; i++) {
+                    if (ingestJobState.getIngestJobContext().fileIngestIsCancelled()) {
+                        return;
+                    }
+                    Thread.sleep(FILE_UPLOAD_RETRY_SLEEP_MILLIS);
+                }
             }
 
             notifyWarning(
-- 
GitLab