From 541be66a1fa830e37baa721099dbacd31734b499 Mon Sep 17 00:00:00 2001
From: William Schaefer <wschaefer@basistech.net>
Date: Fri, 19 Oct 2018 15:54:27 -0400
Subject: [PATCH] add max retry amount of 20 to aquiring case db connection to
 help with debugging 4319

---
 .../java/src/org/sleuthkit/datamodel/SleuthkitCase.java     | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java
index 1b1d74871..9d7942342 100644
--- a/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java
+++ b/bindings/java/src/org/sleuthkit/datamodel/SleuthkitCase.java
@@ -9500,6 +9500,7 @@ public CaseDbConnection getPooledConnection() throws SQLException {
 	abstract class CaseDbConnection {
 
 		static final int SLEEP_LENGTH_IN_MILLISECONDS = 5000;
+		static final int MAX_RETRIES = 20; //MAX_RETRIES * SLEEP_LENGTH_IN_MILLESECONDS = max time to hang attempting connection
 
 		private class CreateStatement implements DbCommand {
 
@@ -9835,16 +9836,19 @@ private final class SQLiteConnection extends CaseDbConnection {
 
 		@Override
 		void executeCommand(DbCommand command) throws SQLException {
+			int retryCounter = 0;
 			while (true) {
 				try {
 					command.execute(); // Perform the operation
 					break;
 				} catch (SQLException ex) {
-					if (ex.getErrorCode() == SQLITE_BUSY_ERROR || ex.getErrorCode() == DATABASE_LOCKED_ERROR) {
+					if ((ex.getErrorCode() == SQLITE_BUSY_ERROR || ex.getErrorCode() == DATABASE_LOCKED_ERROR) && retryCounter < MAX_RETRIES) {
 						try {
+							
 							// We do not notify of error here, as this is not an
 							// error condition. It is likely a temporary busy or
 							// locked issue and we will retry.
+							retryCounter++;
 							Thread.sleep(SLEEP_LENGTH_IN_MILLISECONDS);
 						} catch (InterruptedException exp) {
 							Logger.getLogger(SleuthkitCase.class.getName()).log(Level.WARNING, "Unexpectedly unable to wait for database.", exp);
-- 
GitLab