Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
added timeout for httpd-sockets during read
orbiter24db55a54103
diff --git a/source/de/anomic/http/httpc.java b/source/de/anomic/http/httpc.javaindex f509e557d..69ed0b944 100644--- a/source/de/anomic/http/httpc.java+++ b/source/de/anomic/http/httpc.java@@ -111,6 +111,7 @@ public final class httpc {private static final String vDATE = "20040602";public static String userAgent;private static final int terminalMaxLength = 30000;+ private static final long terminalMaxTime = 60000;private static final TimeZone GMTTimeZone = TimeZone.getTimeZone("GMT");/*** This string is initialized on loading of this class and contains@@ -1708,7 +1709,7 @@ do upload}// reads in the http header, right now, right here- byte[] b = serverCore.receive(httpc.this.clientInput, httpc.this.readLineBuffer, terminalMaxLength, false);+ byte[] b = serverCore.receive(httpc.this.clientInput, httpc.this.readLineBuffer, terminalMaxLength, terminalMaxTime, false);if (b == null) {// the server has meanwhile disconnectedthis.statusCode = 503;@@ -1727,7 +1728,7 @@ do uploadif ((this.statusCode==500)&&(this.statusText.equals("status line parse error"))) {// flush in anything that comes without parsing- while ((b != null) && (b.length != 0)) b = serverCore.receive(httpc.this.clientInput, httpc.this.readLineBuffer, terminalMaxLength, false);+ while ((b != null) && (b.length != 0)) b = serverCore.receive(httpc.this.clientInput, httpc.this.readLineBuffer, terminalMaxLength, terminalMaxTime, false);return; // in bad mood}@@ -1735,13 +1736,13 @@ do uploadif (this.statusCode == 400) {// bad request// flush in anything that comes without parsing- while ((b = serverCore.receive(httpc.this.clientInput, httpc.this.readLineBuffer, terminalMaxLength, false)).length != 0) {}+ while ((b = serverCore.receive(httpc.this.clientInput, httpc.this.readLineBuffer, terminalMaxLength, terminalMaxTime, false)).length != 0) {}return; // in bad mood}// at this point we should have a valid response. read in the header propertiesString key = "";- while ((b = serverCore.receive(httpc.this.clientInput, httpc.this.readLineBuffer, terminalMaxLength, false)) != null) {+ while ((b = serverCore.receive(httpc.this.clientInput, httpc.this.readLineBuffer, terminalMaxLength, terminalMaxTime, false)) != null) {if (b.length == 0) break;buffer = new String(b);buffer=buffer.trim();diff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.javaindex 355c581c4..b75d71bc8 100644--- a/source/de/anomic/server/serverCore.java+++ b/source/de/anomic/server/serverCore.java@@ -1004,7 +1004,7 @@ public final class serverCore extends serverAbstractThread implements serverThre}public byte[] readLine() {- return receive(this.in, this.readLineBuffer, serverCore.this.commandMaxLength, false);+ return receive(this.in, this.readLineBuffer, serverCore.this.commandMaxLength, serverCore.this.timeout, false);}/**@@ -1304,16 +1304,18 @@ public final class serverCore extends serverAbstractThread implements serverThre}- public static byte[] receive(PushbackInputStream pbis, serverByteBuffer readLineBuffer, int maxSize, boolean logerr) {+ public static byte[] receive(PushbackInputStream pbis, serverByteBuffer readLineBuffer, int maxSize, long timeout, boolean logerr) {// reuse an existing linebufferreadLineBuffer.reset();int bufferSize = 0, b = 0;try {+ long start = System.currentTimeMillis();while ((b = pbis.read()) > 31) {readLineBuffer.write(b);- if (bufferSize++ > maxSize) break;+ if (bufferSize++ > maxSize) break;+ if ((System.currentTimeMillis() - start > timeout)) break;}// we have catched a possible line enddiff --git a/source/yacy.java b/source/yacy.javaindex eef46b762..99fd8ae31 100644--- a/source/yacy.java+++ b/source/yacy.java@@ -324,8 +324,7 @@ public final class yacy {yacyVersion.latestRelease = version;// read environment- int timeout = Integer.parseInt(sb.getConfig("httpdTimeout", "60000"));- if (timeout < 60000) timeout = 60000;+ int timeout = Math.max(20000, Integer.parseInt(sb.getConfig("httpdTimeout", "20000")));// create some directoriesfinal File htRootPath = new File(homePath, sb.getConfig("htRootPath", "htroot"));