Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
catch TimeoutException during ping and do not delete yacy.conf during prereadconfigfile found a situation after crash (reboot) with existing running semaphore but YaCy not running. Ping generated exception which finally deleted the conf file (during pre-read procedure) - change to ping (catch exception solved it) - additionally removed delete yacy.conf file (if needed we need to make a backup)
reger8284ea751a6f
diff --git a/source/net/yacy/cora/protocol/Scanner.java b/source/net/yacy/cora/protocol/Scanner.javaindex d1daa4d4c..6d11388aa 100644--- a/source/net/yacy/cora/protocol/Scanner.java+++ b/source/net/yacy/cora/protocol/Scanner.java@@ -151,7 +151,6 @@ public class Scanner {}if (access != Access.unknown) Scanner.this.services.put(this, access);}- } catch (final ExecutionException e) {} catch (final OutOfMemoryError e) {}}diff --git a/source/net/yacy/cora/protocol/TimeoutRequest.java b/source/net/yacy/cora/protocol/TimeoutRequest.javaindex 33aefad13..21270a726 100644--- a/source/net/yacy/cora/protocol/TimeoutRequest.java+++ b/source/net/yacy/cora/protocol/TimeoutRequest.java@@ -108,33 +108,37 @@ public class TimeoutRequest<E> {* @param uri* @param timeout* @return true if the server exists and replies within the given time-out- * @throws ExecutionException*/- public static boolean ping(final String host, final int port, final int timeout) throws ExecutionException {- return new TimeoutRequest<Boolean>(new Callable<Boolean>() {- @Override- public Boolean call() {- //long time = System.currentTimeMillis();- try {- final Socket socket = new Socket();- //System.out.println("PING socket create = " + (System.currentTimeMillis() - time) + " ms (" + host + ":" + port + ")"); time = System.currentTimeMillis();- socket.connect(new InetSocketAddress(host, port), timeout);- //System.out.println("PING socket connect = " + (System.currentTimeMillis() - time) + " ms (" + host + ":" + port + ")"); time = System.currentTimeMillis();- if (socket.isConnected()) {- socket.close();- return Boolean.TRUE;+ public static boolean ping(final String host, final int port, final int timeout) {+ try {+ return new TimeoutRequest<Boolean>(new Callable<Boolean>() {+ @Override+ public Boolean call() {+ //long time = System.currentTimeMillis();+ try {+ final Socket socket = new Socket();+ //System.out.println("PING socket create = " + (System.currentTimeMillis() - time) + " ms (" + host + ":" + port + ")"); time = System.currentTimeMillis();+ socket.connect(new InetSocketAddress(host, port), timeout);+ //System.out.println("PING socket connect = " + (System.currentTimeMillis() - time) + " ms (" + host + ":" + port + ")"); time = System.currentTimeMillis();+ if (socket.isConnected()) {+ socket.close();+ return Boolean.TRUE;+ }+ //System.out.println("PING socket close = " + (System.currentTimeMillis() - time) + " ms (" + host + ":" + port + ")"); time = System.currentTimeMillis();+ return Boolean.FALSE;+ } catch (final UnknownHostException e) {+ //System.out.println("PING socket UnknownHostException = " + (System.currentTimeMillis() - time) + " ms (" + host + ":" + port + ")"); time = System.currentTimeMillis();+ return Boolean.FALSE;+ } catch (final IOException e) {+ //System.out.println("PING socket IOException = " + (System.currentTimeMillis() - time) + " ms (" + host + ":" + port + ")"); time = System.currentTimeMillis();+ return Boolean.FALSE;}- //System.out.println("PING socket close = " + (System.currentTimeMillis() - time) + " ms (" + host + ":" + port + ")"); time = System.currentTimeMillis();- return Boolean.FALSE;- } catch (final UnknownHostException e) {- //System.out.println("PING socket UnknownHostException = " + (System.currentTimeMillis() - time) + " ms (" + host + ":" + port + ")"); time = System.currentTimeMillis();- return Boolean.FALSE;- } catch (final IOException e) {- //System.out.println("PING socket IOException = " + (System.currentTimeMillis() - time) + " ms (" + host + ":" + port + ")"); time = System.currentTimeMillis();- return Boolean.FALSE;}- }- }).call(timeout).booleanValue();+ }).call(timeout).booleanValue();++ } catch (ExecutionException ex) { // may happen on Timeout (see call)+ return false;+ }}/**diff --git a/source/net/yacy/migration.java b/source/net/yacy/migration.javaindex ad32d49e1..630c22692 100644--- a/source/net/yacy/migration.java+++ b/source/net/yacy/migration.java@@ -74,12 +74,10 @@ public class migration {// ssl/https support currently on hardcoded default port 8443 (v1.67/9563)// make sure YaCy can start (disable ssl/https support if port is used)if (sb.getConfigBool("server.https", false)) {- try {- if (TimeoutRequest.ping("127.0.0.1", 8443, 3000)) {- sb.setConfig("server.https", false);- ConcurrentLog.info("MIGRATION", "disabled https support (reason: default port 8443 already used)");- }- } catch (ExecutionException ex) { }+ if (TimeoutRequest.ping("127.0.0.1", 8443, 3000)) {+ sb.setConfig("server.https", false);+ ConcurrentLog.info("MIGRATION", "disabled https support (reason: default port 8443 already used)");+ }}}/*diff --git a/source/net/yacy/search/Switchboard.java b/source/net/yacy/search/Switchboard.javaindex ebeec3e6c..2244ed508 100644--- a/source/net/yacy/search/Switchboard.java+++ b/source/net/yacy/search/Switchboard.java@@ -68,7 +68,6 @@ import java.util.SortedSet;import java.util.TreeMap;import java.util.TreeSet;import java.util.concurrent.ConcurrentHashMap;-import java.util.concurrent.ExecutionException;import java.util.concurrent.LinkedBlockingQueue;import java.util.concurrent.Semaphore;import java.util.concurrent.atomic.AtomicInteger;@@ -294,14 +293,11 @@ public final class Switchboard extends serverSwitch {sb = this;// check if port is already occupiedfinal int port = getConfigInt("port", 8090);- try {- if ( TimeoutRequest.ping(Domains.LOCALHOST, port, 500) ) {- throw new RuntimeException(+ if (TimeoutRequest.ping(Domains.LOCALHOST, port, 500)) {+ throw new RuntimeException("a server is already running on the YaCy port "- + port- + "; possibly another YaCy process has not terminated yet. Please stop YaCy before running a new instance.");- }- } catch (final ExecutionException e1 ) {+ + port+ + "; possibly another YaCy process has not terminated yet. Please stop YaCy before running a new instance.");}MemoryTracker.startSystemProfiling();diff --git a/source/net/yacy/yacy.java b/source/net/yacy/yacy.javaindex 6aed90860..1b58a5e4b 100644--- a/source/net/yacy/yacy.java+++ b/source/net/yacy/yacy.java@@ -559,10 +559,12 @@ public final class yacy {delete(lockFile);}}- } catch (Throwable ex) {+ } catch (IOException ex) {+ System.err.println("ERROR: config file seems to be corrupt");+ System.err.println("ERROR: if problem persists, delete file");+ System.err.println(configFile.getAbsolutePath());ConcurrentLog.logException(ex);- ConcurrentLog.severe("Startup", "cannot read " + configFile.toString() + ", removing old file");- configFile.delete();+ ConcurrentLog.severe("Startup", "cannot read " + configFile.toString() + ", please delete the corrupted file if problem persits");}}}