Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-746 NutchBeanConstructor does not close NutchBean upon contextDestroyed, causing resource leak in the container.

Andrzej Bialeckib9f7a6e21c7b
diff --git a/CHANGES.txt b/CHANGES.txt
index f8aedc622..994f7d46e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,11 @@ Nutch Change Log
Unreleased Changes
+* NUTCH-746 NutchBeanConstructor does not close NutchBean upon contextDestroyed,
+ causing resource leak in the container. (Kirby Bohling via ab)
+
+* NUTCH-772 Upgrade Nutch to use Lucene 2.9.1 (ab)
+
* NUTCH-760 Allow field mapping from Nutch to Solr index (David Stuart, ab)
* NUTCH-761 Avoid cloning CrawlDatum in CrawlDbReducer (Julien Nioche, ab)
diff --git a/src/java/org/apache/nutch/searcher/NutchBean.java b/src/java/org/apache/nutch/searcher/NutchBean.java
index a2dc36d0f..4ffddce44 100644
--- a/src/java/org/apache/nutch/searcher/NutchBean.java
+++ b/src/java/org/apache/nutch/searcher/NutchBean.java
@@ -413,7 +413,24 @@ implements SearchBean, SegmentBean, HitInlinks, Closeable {
*/
public static class NutchBeanConstructor implements ServletContextListener {
- public void contextDestroyed(ServletContextEvent sce) { }
+ public void contextDestroyed(ServletContextEvent sce) {
+ final ServletContext context = sce.getServletContext();
+
+ LOG.info("Closing Bean");
+ try {
+ Object tmp = context.getAttribute(NutchBean.KEY);
+
+ if (tmp instanceof NutchBean) {
+ NutchBean bean = (NutchBean) tmp;
+ bean.close();
+ } else {
+ LOG.warn("No bean configured, or the wrong type? Potential PermGen leak, or startup problem.");
+ }
+ }
+ catch (final IOException ex) {
+ LOG.error(StringUtils.stringifyException(ex));
+ }
+ }
public void contextInitialized(ServletContextEvent sce) {
final ServletContext app = sce.getServletContext();