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)
pull/1/head
reger 10 years ago
parent dc14824814
commit 8284ea751a

@ -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) {
}
}

@ -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;
}
}
/**

@ -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)");
}
}
}
/*

@ -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 occupied
final 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();

@ -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");
}
}
}

Loading…
Cancel
Save