From fbd722bade8dbadb63ea1ef07ed84f9e880adbd5 Mon Sep 17 00:00:00 2001 From: Mark McKinnon Date: Fri, 30 May 2025 16:04:49 -0400 Subject: [PATCH 1/2] Update CoordinationServiceUtils.java Change timeout from 3000 to 15000 for options panel validation --- .../coordinationservice/utils/CoordinationServiceUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/coordinationservice/utils/CoordinationServiceUtils.java b/Core/src/org/sleuthkit/autopsy/coordinationservice/utils/CoordinationServiceUtils.java index 28f2a340e91..c4908f41859 100755 --- a/Core/src/org/sleuthkit/autopsy/coordinationservice/utils/CoordinationServiceUtils.java +++ b/Core/src/org/sleuthkit/autopsy/coordinationservice/utils/CoordinationServiceUtils.java @@ -28,7 +28,7 @@ */ public final class CoordinationServiceUtils { - private static final int ZOOKEEPER_SESSION_TIMEOUT_MILLIS = 3000; + private static final int ZOOKEEPER_SESSION_TIMEOUT_MILLIS = 15000; private static final int ZOOKEEPER_CONNECTION_TIMEOUT_MILLIS = 15000; /** From ef43ff392912d6510820230c819ee80ff06b0443 Mon Sep 17 00:00:00 2001 From: Mark McKinnon Date: Thu, 19 Jun 2025 22:39:33 -0400 Subject: [PATCH 2/2] Update CoordinationServiceUtils.java Change code to use ruok/imok --- .../utils/CoordinationServiceUtils.java | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/coordinationservice/utils/CoordinationServiceUtils.java b/Core/src/org/sleuthkit/autopsy/coordinationservice/utils/CoordinationServiceUtils.java index c4908f41859..5e8e88698f8 100755 --- a/Core/src/org/sleuthkit/autopsy/coordinationservice/utils/CoordinationServiceUtils.java +++ b/Core/src/org/sleuthkit/autopsy/coordinationservice/utils/CoordinationServiceUtils.java @@ -18,9 +18,13 @@ */ package org.sleuthkit.autopsy.coordinationservice.utils; +import java.io.BufferedReader; +import java.io.InputStreamReader; import java.io.IOException; -import org.apache.zookeeper.WatchedEvent; -import org.apache.zookeeper.ZooKeeper; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.net.SocketTimeoutException; /** * A utility class for coordination service and ZooKeeper. This class is in a @@ -28,9 +32,8 @@ */ public final class CoordinationServiceUtils { - private static final int ZOOKEEPER_SESSION_TIMEOUT_MILLIS = 15000; - private static final int ZOOKEEPER_CONNECTION_TIMEOUT_MILLIS = 15000; - + private static final int ZOOKEEPER_SESSION_TIMEOUT_MILLIS = 3000; + /** * Determines if ZooKeeper is accessible with the current settings. Closes * the connection prior to returning. @@ -42,22 +45,28 @@ public final class CoordinationServiceUtils { */ public static boolean isZooKeeperAccessible(String hostName, String port) throws InterruptedException, IOException { boolean result = false; - Object workerThreadWaitNotifyLock = new Object(); - String connectString = hostName + ":" + port; - ZooKeeper zooKeeper = new ZooKeeper(connectString, ZOOKEEPER_SESSION_TIMEOUT_MILLIS, - (WatchedEvent event) -> { - synchronized (workerThreadWaitNotifyLock) { - workerThreadWaitNotifyLock.notify(); - } - }); - synchronized (workerThreadWaitNotifyLock) { - workerThreadWaitNotifyLock.wait(ZOOKEEPER_CONNECTION_TIMEOUT_MILLIS); - } - ZooKeeper.States state = zooKeeper.getState(); - if (state == ZooKeeper.States.CONNECTED || state == ZooKeeper.States.CONNECTEDREADONLY) { - result = true; + + try { + + Socket socket = new Socket(); + socket.connect(new InetSocketAddress(hostName, Integer.valueOf(port)), ZOOKEEPER_SESSION_TIMEOUT_MILLIS); + socket.setSoTimeout(ZOOKEEPER_SESSION_TIMEOUT_MILLIS); + + OutputStream out = socket.getOutputStream(); + out.write("ruok".getBytes()); + out.flush(); + + BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); + String response = reader.readLine(); + + socket.close(); + + if (response.toLowerCase().contains("imok")) { + result = true; + } + } catch (SocketTimeoutException e) { + result = false; } - zooKeeper.close(); return result; } }