From 0d90bbcc9c3af740a700fd4ceb69c39e14f1d6f7 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Sat, 1 Aug 2020 13:06:25 -0700 Subject: [PATCH] Add escape hatch to while loop --- .../ca/uhn/fhir/jpa/empi/svc/EmpiPersonDeletingSvc.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiPersonDeletingSvc.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiPersonDeletingSvc.java index fa759d8f19a..cd842fd89bf 100644 --- a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiPersonDeletingSvc.java +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiPersonDeletingSvc.java @@ -41,6 +41,10 @@ import static org.slf4j.LoggerFactory.getLogger; @Service public class EmpiPersonDeletingSvc { private static final Logger ourLog = getLogger(EmpiPersonDeletingSvc.class); + /** + * This is here for the case of possible infinite loops. Technically batch conflict deletion should handle this, but this is an escape hatch. + */ + private static final int MAXIMUM_DELETE_ATTEMPTS = 100000; @Autowired private DaoRegistry myDaoRegistry; @@ -60,8 +64,10 @@ public class EmpiPersonDeletingSvc { theLongs.stream().forEach(pid -> deleteCascade(pid, deleteConflictList)); IFhirResourceDao personDao = myDaoRegistry.getResourceDao("Person"); - while (!deleteConflictList.isEmpty()) { + int batchCount = 0; + while (!deleteConflictList.isEmpty() && batchCount < MAXIMUM_DELETE_ATTEMPTS) { deleteConflictBatch(deleteConflictList, personDao); + batchCount += 1; } }