Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

- fixed a memory leak (or bad usage) during parsing/snippet fetch - more logging for errors

Michael Peter Christen8efc1c107891
diff --git a/source/de/anomic/http/server/HTTPDFileHandler.java b/source/de/anomic/http/server/HTTPDFileHandler.java
index 7a719c44c..d0b2b718f 100644
--- a/source/de/anomic/http/server/HTTPDFileHandler.java
+++ b/source/de/anomic/http/server/HTTPDFileHandler.java
@@ -570,24 +570,11 @@ public final class HTTPDFileHandler {
if ((targetClass != null) && (path.endsWith("png"))) {
// call an image-servlet to produce an on-the-fly - generated image
Object img = null;
- try {
- requestHeader.put(HeaderFramework.CONNECTION_PROP_CLIENTIP, (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP));
- requestHeader.put(HeaderFramework.CONNECTION_PROP_PATH, path);
- requestHeader.put(HeaderFramework.CONNECTION_PROP_EXT, "png");
- // in case that there are no args given, args = null or empty hashmap
- img = invokeServlet(targetClass, requestHeader, args);
- } catch (final InvocationTargetException e) {
- theLogger.logSevere("INTERNAL ERROR: " + e.toString() + ":" +
- e.getMessage() +
- " target exception at " + targetClass + ": " +
- e.getTargetException().toString() + ":" +
- e.getTargetException().getMessage() +
- "; java.awt.graphicsenv='" + System.getProperty("java.awt.graphicsenv","") + "'");
- Log.logException(e);
- Log.logException(e.getCause());
- Log.logException(e.getTargetException());
- targetClass = null;
- }
+ requestHeader.put(HeaderFramework.CONNECTION_PROP_CLIENTIP, (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP));
+ requestHeader.put(HeaderFramework.CONNECTION_PROP_PATH, path);
+ requestHeader.put(HeaderFramework.CONNECTION_PROP_EXT, "png");
+ // in case that there are no args given, args = null or empty hashmap
+ img = invokeServlet(targetClass, requestHeader, args);
if (img == null) {
// error with image generation; send file-not-found
HTTPDemon.sendRespondError(conProp, out, 3, 404, "File not Found", null, null);
@@ -928,68 +915,56 @@ public final class HTTPDFileHandler {
// call rewrite-class
if (targetClass != null) {
- // CGI-class: call the class to create a property for rewriting
- try {
- requestHeader.put(HeaderFramework.CONNECTION_PROP_CLIENTIP, (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP));
- requestHeader.put(HeaderFramework.CONNECTION_PROP_PATH, path);
- final int ep = path.lastIndexOf(".");
- requestHeader.put(HeaderFramework.CONNECTION_PROP_EXT, path.substring(ep + 1));
- // in case that there are no args given, args = null or empty hashmap
- final Object tmp = invokeServlet(targetClass, requestHeader, args);
- if (tmp == null) {
- // if no args given, then tp will be an empty Hashtable object (not null)
- templatePatterns = new servletProperties();
- } else if (tmp instanceof servletProperties) {
- templatePatterns = (servletProperties) tmp;
- } else {
- templatePatterns = new servletProperties((serverObjects) tmp);
- }
- // check if the servlets requests authentication
- if (templatePatterns.containsKey(serverObjects.ACTION_AUTHENTICATE)) {
- // handle brute-force protection
- if (realmProp != null) {
- Log.logInfo("HTTPD", "dynamic log-in for account 'admin' in http file handler for path '" + path + "' from host '" + clientIP + "'");
- final Integer attempts = serverCore.bfHost.get(clientIP);
- if (attempts == null)
- serverCore.bfHost.put(clientIP, Integer.valueOf(1));
- else
- serverCore.bfHost.put(clientIP, Integer.valueOf(attempts.intValue() + 1));
- }
- // send authentication request to browser
- final ResponseHeader headers = getDefaultHeaders(path);
- headers.put(RequestHeader.WWW_AUTHENTICATE,"Basic realm=\"" + templatePatterns.get(serverObjects.ACTION_AUTHENTICATE, "") + "\"");
- HTTPDemon.sendRespondHeader(conProp,out,httpVersion,401,headers);
- return;
- } else if (templatePatterns.containsKey(serverObjects.ACTION_LOCATION)) {
- String location = templatePatterns.get(serverObjects.ACTION_LOCATION, "");
- if (location.length() == 0) location = path;
-
- final ResponseHeader headers = getDefaultHeaders(path);
- headers.setAdditionalHeaderProperties(templatePatterns.getOutgoingHeader().getAdditionalHeaderProperties()); //put the cookies into the new header TODO: can we put all headerlines, without trouble?
- headers.put(HeaderFramework.LOCATION,location);
- HTTPDemon.sendRespondHeader(conProp,out,httpVersion,302,headers);
- return;
- }
- // add the application version, the uptime and the client name to every rewrite table
- templatePatterns.put(servletProperties.PEER_STAT_VERSION, yacyBuildProperties.getVersion());
- templatePatterns.put(servletProperties.PEER_STAT_UPTIME, ((System.currentTimeMillis() - serverCore.startupTime) / 1000) / 60); // uptime in minutes
- templatePatterns.putHTML(servletProperties.PEER_STAT_CLIENTNAME, sb.peers.mySeed().getName());
- templatePatterns.putHTML(servletProperties.PEER_STAT_CLIENTID, ((Switchboard) switchboard).peers.myID());
- templatePatterns.put(servletProperties.PEER_STAT_MYTIME, GenericFormatter.SHORT_SECOND_FORMATTER.format());
- final Seed myPeer = sb.peers.mySeed();
- templatePatterns.put("newpeer", myPeer.getAge() >= 1 ? 0 : 1);
- templatePatterns.putHTML("newpeer_peerhash", myPeer.hash);
- //System.out.println("respond props: " + ((tp == null) ? "null" : tp.toString())); // debug
- } catch (final InvocationTargetException e) {
- if (e.getCause() instanceof InterruptedException) {
- throw new InterruptedException(e.getCause().getMessage());
+ requestHeader.put(HeaderFramework.CONNECTION_PROP_CLIENTIP, (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP));
+ requestHeader.put(HeaderFramework.CONNECTION_PROP_PATH, path);
+ final int ep = path.lastIndexOf(".");
+ requestHeader.put(HeaderFramework.CONNECTION_PROP_EXT, path.substring(ep + 1));
+ // in case that there are no args given, args = null or empty hashmap
+ final Object tmp = invokeServlet(targetClass, requestHeader, args);
+ if (tmp == null) {
+ // if no args given, then tp will be an empty Hashtable object (not null)
+ templatePatterns = new servletProperties();
+ } else if (tmp instanceof servletProperties) {
+ templatePatterns = (servletProperties) tmp;
+ } else {
+ templatePatterns = new servletProperties((serverObjects) tmp);
+ }
+ // check if the servlets requests authentication
+ if (templatePatterns.containsKey(serverObjects.ACTION_AUTHENTICATE)) {
+ // handle brute-force protection
+ if (realmProp != null) {
+ Log.logInfo("HTTPD", "dynamic log-in for account 'admin' in http file handler for path '" + path + "' from host '" + clientIP + "'");
+ final Integer attempts = serverCore.bfHost.get(clientIP);
+ if (attempts == null)
+ serverCore.bfHost.put(clientIP, Integer.valueOf(1));
+ else
+ serverCore.bfHost.put(clientIP, Integer.valueOf(attempts.intValue() + 1));
}
- Log.logException(e);
- Log.logException(e.getCause());
- Log.logException(e.getTargetException());
- targetClass = null;
- throw e;
+ // send authentication request to browser
+ final ResponseHeader headers = getDefaultHeaders(path);
+ headers.put(RequestHeader.WWW_AUTHENTICATE,"Basic realm=\"" + templatePatterns.get(serverObjects.ACTION_AUTHENTICATE, "") + "\"");
+ HTTPDemon.sendRespondHeader(conProp,out,httpVersion,401,headers);
+ return;
+ } else if (templatePatterns.containsKey(serverObjects.ACTION_LOCATION)) {
+ String location = templatePatterns.get(serverObjects.ACTION_LOCATION, "");
+ if (location.length() == 0) location = path;
+
+ final ResponseHeader headers = getDefaultHeaders(path);
+ headers.setAdditionalHeaderProperties(templatePatterns.getOutgoingHeader().getAdditionalHeaderProperties()); //put the cookies into the new header TODO: can we put all headerlines, without trouble?
+ headers.put(HeaderFramework.LOCATION,location);
+ HTTPDemon.sendRespondHeader(conProp,out,httpVersion,302,headers);
+ return;
}
+ // add the application version, the uptime and the client name to every rewrite table
+ templatePatterns.put(servletProperties.PEER_STAT_VERSION, yacyBuildProperties.getVersion());
+ templatePatterns.put(servletProperties.PEER_STAT_UPTIME, ((System.currentTimeMillis() - serverCore.startupTime) / 1000) / 60); // uptime in minutes
+ templatePatterns.putHTML(servletProperties.PEER_STAT_CLIENTNAME, sb.peers.mySeed().getName());
+ templatePatterns.putHTML(servletProperties.PEER_STAT_CLIENTID, ((Switchboard) switchboard).peers.myID());
+ templatePatterns.put(servletProperties.PEER_STAT_MYTIME, GenericFormatter.SHORT_SECOND_FORMATTER.format());
+ final Seed myPeer = sb.peers.mySeed();
+ templatePatterns.put("newpeer", myPeer.getAge() >= 1 ? 0 : 1);
+ templatePatterns.putHTML("newpeer_peerhash", myPeer.hash);
+ //System.out.println("respond props: " + ((tp == null) ? "null" : tp.toString())); // debug
nocache = true;
}
@@ -1390,11 +1365,17 @@ public final class HTTPDFileHandler {
return m;
}
- private static final Object invokeServlet(final File targetClass, final RequestHeader request, final serverObjects args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
+ private static final Object invokeServlet(final File targetClass, final RequestHeader request, final serverObjects args) {
try {
return rewriteMethod(targetClass).invoke(null, new Object[] {request, args, switchboard});
- } catch (final OutOfMemoryError e) {
+ } catch (final Throwable e) {
+ theLogger.logSevere("INTERNAL ERROR: " + e.toString() + ":" +
+ e.getMessage() +
+ " target exception at " + targetClass + ": " +
+ "; java.awt.graphicsenv='" + System.getProperty("java.awt.graphicsenv","") + "'");
Log.logException(e);
+ Log.logException(e.getCause());
+ if (e instanceof InvocationTargetException) Log.logException(((InvocationTargetException) e).getTargetException());
return null;
}
}
diff --git a/source/net/yacy/document/parser/html/TransformerWriter.java b/source/net/yacy/document/parser/html/TransformerWriter.java
index d1be4f3df..187e60885 100644
--- a/source/net/yacy/document/parser/html/TransformerWriter.java
+++ b/source/net/yacy/document/parser/html/TransformerWriter.java
@@ -80,7 +80,7 @@ public final class TransformerWriter extends Writer {
final Transformer transformer,
final boolean passbyIfBinarySuspect
) {
- this(outStream, charSet, scraper, transformer, passbyIfBinarySuspect, 4096);
+ this(outStream, charSet, scraper, transformer, passbyIfBinarySuspect, 64);
}
public TransformerWriter(
diff --git a/source/net/yacy/document/parser/htmlParser.java b/source/net/yacy/document/parser/htmlParser.java
index 2c22f73cf..56e1e2fee 100644
--- a/source/net/yacy/document/parser/htmlParser.java
+++ b/source/net/yacy/document/parser/htmlParser.java
@@ -200,7 +200,7 @@ public class htmlParser extends AbstractParser implements Parser {
// parsing the content
final ContentScraper scraper = new ContentScraper(location, maxLinks);
- final TransformerWriter writer = new TransformerWriter(null,null,scraper,null,false, Math.max(4096, sourceStream.available()));
+ final TransformerWriter writer = new TransformerWriter(null,null,scraper,null,false, Math.max(64, Math.min(4096, sourceStream.available())));
try {
FileUtils.copy(sourceStream, writer, c);
} catch (final IOException e) {
diff --git a/source/net/yacy/kelondro/workflow/InstantBlockingThread.java b/source/net/yacy/kelondro/workflow/InstantBlockingThread.java
index 26db9dd0f..0be898322 100644
--- a/source/net/yacy/kelondro/workflow/InstantBlockingThread.java
+++ b/source/net/yacy/kelondro/workflow/InstantBlockingThread.java
@@ -108,28 +108,14 @@ public class InstantBlockingThread<J extends WorkflowJob> extends AbstractBlocki
try {
out = (J) this.jobExecMethod.invoke(this.environment, new Object[]{next});
- } catch (final IllegalAccessException e) {
+ } catch (final Throwable e) {
Log.logSevere(BLOCKINGTHREAD, "Internal Error in serverInstantThread.job: " + e.getMessage());
Log.logSevere(BLOCKINGTHREAD, "shutting down thread '" + getName() + "'");
- terminate(false);
- } catch (final IllegalArgumentException e) {
- Log.logSevere(BLOCKINGTHREAD, "Internal Error in serverInstantThread.job: " + e.getMessage());
- Log.logSevere(BLOCKINGTHREAD, "shutting down thread '" + getName() + "'");
- terminate(false);
- } catch (final InvocationTargetException e) {
- final String targetException = e.getTargetException().getMessage();
+ final Throwable targetException = (e instanceof InvocationTargetException) ? ((InvocationTargetException) e).getTargetException() : null;
Log.logException(e);
Log.logException(e.getCause());
- Log.logException(e.getTargetException());
- if ((targetException != null) &&
- ((targetException.indexOf("heap space",0) > 0) ||
- (targetException.indexOf("NullPointerException",0) > 0))) {
- Log.logException(e.getTargetException());
- }
- Log.logSevere(BLOCKINGTHREAD, "Runtime Error in serverInstantThread.job, thread '" + getName() + "': " + e.getMessage() + "; target exception: " + targetException, e.getTargetException());
- } catch (final OutOfMemoryError e) {
- Log.logSevere(BLOCKINGTHREAD, "OutOfMemory Error in serverInstantThread.job, thread '" + getName() + "': " + e.getMessage());
- Log.logException(e);
+ if (targetException != null) Log.logException(targetException);
+ Log.logSevere(BLOCKINGTHREAD, "Runtime Error in serverInstantThread.job, thread '" + getName() + "': " + e.getMessage());
}
instantThreadCounter--;
jobs.remove(this.handle);