You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by tk...@apache.org on 2015/10/27 02:58:19 UTC
[1/3] nifi git commit: NIFI-1073 fixed resource leaks and used nifi
util for ByteArrayInputStream in CaptureServlet
Repository: nifi
Updated Branches:
refs/heads/NIFI-1073 21983c157 -> 2fa02f31c
NIFI-1073 fixed resource leaks and used nifi util for ByteArrayInputStream in CaptureServlet
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/aef73fdc
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/aef73fdc
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/aef73fdc
Branch: refs/heads/NIFI-1073
Commit: aef73fdc0d97c8e499eba9536ba47e548cc0b43f
Parents: 21983c1
Author: Tony Kurc <tr...@gmail.com>
Authored: Mon Oct 26 21:00:27 2015 -0400
Committer: Tony Kurc <tr...@gmail.com>
Committed: Mon Oct 26 21:29:50 2015 -0400
----------------------------------------------------------------------
.../nifi/processors/WriteResourceToStream.java | 11 +++++++---
.../processors/standard/ListFileTransfer.java | 2 ++
.../processors/standard/CaptureServlet.java | 12 ++++++----
.../DistributedMapCacheClientService.java | 23 +++++++-------------
4 files changed, 26 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi/blob/aef73fdc/nifi-external/nifi-example-bundle/nifi-nifi-example-processors/src/main/java/org/apache/nifi/processors/WriteResourceToStream.java
----------------------------------------------------------------------
diff --git a/nifi-external/nifi-example-bundle/nifi-nifi-example-processors/src/main/java/org/apache/nifi/processors/WriteResourceToStream.java b/nifi-external/nifi-example-bundle/nifi-nifi-example-processors/src/main/java/org/apache/nifi/processors/WriteResourceToStream.java
index 5d595b4..c840ce8 100644
--- a/nifi-external/nifi-example-bundle/nifi-nifi-example-processors/src/main/java/org/apache/nifi/processors/WriteResourceToStream.java
+++ b/nifi-external/nifi-example-bundle/nifi-nifi-example-processors/src/main/java/org/apache/nifi/processors/WriteResourceToStream.java
@@ -17,6 +17,7 @@
package org.apache.nifi.processors;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collections;
import java.util.HashSet;
@@ -34,6 +35,7 @@ import org.apache.nifi.processor.ProcessorInitializationContext;
import org.apache.nifi.processor.Relationship;
import org.apache.nifi.processor.exception.ProcessException;
import org.apache.nifi.processor.io.OutputStreamCallback;
+import org.apache.nifi.util.file.FileUtils;
@Tags({ "example", "resources" })
@CapabilityDescription("This example processor loads a resource from the nar and writes it to the FlowFile content")
@@ -57,13 +59,16 @@ public class WriteResourceToStream extends AbstractProcessor {
relationships.add(REL_SUCCESS);
relationships.add(REL_FAILURE);
this.relationships = Collections.unmodifiableSet(relationships);
-
+ final InputStream resourceStream = Thread.currentThread()
+ .getContextClassLoader().getResourceAsStream("file.txt");
try {
- this.resourceData = IOUtils.toString(Thread.currentThread()
- .getContextClassLoader().getResourceAsStream("file.txt"));
+ this.resourceData = IOUtils.toString(resourceStream);
} catch (IOException e) {
throw new RuntimeException("Unable to load resources", e);
+ } finally {
+ FileUtils.closeQuietly(resourceStream);
}
+
}
@Override
http://git-wip-us.apache.org/repos/asf/nifi/blob/aef73fdc/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListFileTransfer.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListFileTransfer.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListFileTransfer.java
index b6c8c28..ce344ed 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListFileTransfer.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListFileTransfer.java
@@ -29,6 +29,7 @@ import org.apache.nifi.processor.ProcessContext;
import org.apache.nifi.processor.util.StandardValidators;
import org.apache.nifi.processors.standard.util.FileInfo;
import org.apache.nifi.processors.standard.util.FileTransfer;
+import org.apache.nifi.util.file.FileUtils;
public abstract class ListFileTransfer extends AbstractListProcessor<FileInfo> {
public static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder()
@@ -93,6 +94,7 @@ public abstract class ListFileTransfer extends AbstractListProcessor<FileInfo> {
protected List<FileInfo> performListing(final ProcessContext context, final Long minTimestamp) throws IOException {
final FileTransfer transfer = getFileTransfer(context);
final List<FileInfo> listing = transfer.getListing();
+ FileUtils.closeQuietly(transfer);
if (minTimestamp == null) {
return listing;
}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aef73fdc/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/CaptureServlet.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/CaptureServlet.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/CaptureServlet.java
index d6c87d6..a1398f4 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/CaptureServlet.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/CaptureServlet.java
@@ -24,8 +24,9 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.Response.Status;
-import org.apache.activemq.util.ByteArrayOutputStream;
+import org.apache.nifi.stream.io.ByteArrayOutputStream;
import org.apache.nifi.stream.io.StreamUtils;
+import org.apache.nifi.util.file.FileUtils;
public class CaptureServlet extends HttpServlet {
@@ -40,9 +41,12 @@ public class CaptureServlet extends HttpServlet {
@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- StreamUtils.copy(request.getInputStream(), baos);
- this.lastPost = baos.toByteArray();
-
+ try{
+ StreamUtils.copy(request.getInputStream(), baos);
+ this.lastPost = baos.toByteArray();
+ } finally{
+ FileUtils.closeQuietly(baos);
+ }
response.setStatus(Status.OK.getStatusCode());
}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aef73fdc/nifi-nar-bundles/nifi-standard-services/nifi-distributed-cache-services-bundle/nifi-distributed-cache-client-service/src/main/java/org/apache/nifi/distributed/cache/client/DistributedMapCacheClientService.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-distributed-cache-services-bundle/nifi-distributed-cache-client-service/src/main/java/org/apache/nifi/distributed/cache/client/DistributedMapCacheClientService.java b/nifi-nar-bundles/nifi-standard-services/nifi-distributed-cache-services-bundle/nifi-distributed-cache-client-service/src/main/java/org/apache/nifi/distributed/cache/client/DistributedMapCacheClientService.java
index c03dd5a..9d9c741 100644
--- a/nifi-nar-bundles/nifi-standard-services/nifi-distributed-cache-services-bundle/nifi-distributed-cache-client-service/src/main/java/org/apache/nifi/distributed/cache/client/DistributedMapCacheClientService.java
+++ b/nifi-nar-bundles/nifi-standard-services/nifi-distributed-cache-services-bundle/nifi-distributed-cache-client-service/src/main/java/org/apache/nifi/distributed/cache/client/DistributedMapCacheClientService.java
@@ -40,6 +40,7 @@ import org.apache.nifi.ssl.SSLContextService;
import org.apache.nifi.ssl.SSLContextService.ClientAuth;
import org.apache.nifi.stream.io.ByteArrayOutputStream;
import org.apache.nifi.stream.io.DataOutputStream;
+import org.apache.nifi.util.file.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -298,27 +299,19 @@ public class DistributedMapCacheClientService extends AbstractControllerService
if (closed) {
throw new IllegalStateException("Client is closed");
}
-
+ boolean tryToRequeue = true;
final CommsSession session = leaseCommsSession();
try {
return action.execute(session);
} catch (final IOException ioe) {
- try {
- session.close();
- } catch (final IOException ignored) {
- }
-
+ tryToRequeue = false;
throw ioe;
} finally {
- if (!session.isClosed()) {
- if (this.closed) {
- try {
- session.close();
- } catch (final IOException ioe) {
- }
- } else {
- queue.offer(session);
- }
+ if (tryToRequeue == true && this.closed == false) {
+ queue.offer(session);
+ }
+ else{
+ FileUtils.closeQuietly(session);
}
}
}
[2/3] nifi git commit: NIFI-1073 fixed possible, but not realistic,
resource leak in DistributedMapCacheClientService
Posted by tk...@apache.org.
NIFI-1073 fixed possible, but not realistic, resource leak in DistributedMapCacheClientService
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/a5501ac7
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/a5501ac7
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/a5501ac7
Branch: refs/heads/NIFI-1073
Commit: a5501ac77af9e75faf7037072bb84c4ae59e2875
Parents: aef73fd
Author: Tony Kurc <tr...@gmail.com>
Authored: Mon Oct 26 21:35:45 2015 -0400
Committer: Tony Kurc <tr...@gmail.com>
Committed: Mon Oct 26 21:35:45 2015 -0400
----------------------------------------------------------------------
.../nifi/controller/repository/VolatileContentRepository.java | 5 +++++
1 file changed, 5 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi/blob/a5501ac7/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/VolatileContentRepository.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/VolatileContentRepository.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/VolatileContentRepository.java
index 7c7cade..0451812 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/VolatileContentRepository.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/VolatileContentRepository.java
@@ -50,6 +50,7 @@ import org.apache.nifi.processor.DataUnit;
import org.apache.nifi.stream.io.ByteArrayInputStream;
import org.apache.nifi.stream.io.StreamUtils;
import org.apache.nifi.util.NiFiProperties;
+import org.apache.nifi.util.file.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -407,8 +408,12 @@ public class VolatileContentRepository implements ContentRepository {
@Override
public long exportTo(ContentClaim claim, OutputStream destination, long offset, long length) throws IOException {
final InputStream in = read(claim);
+ try {
StreamUtils.skip(in, offset);
StreamUtils.copy(in, destination, length);
+ } finally {
+ FileUtils.closeQuietly(in);
+ }
return length;
}
[3/3] nifi git commit: NIFI-1073 a couple closes that are probably
noops as they were implemented
Posted by tk...@apache.org.
NIFI-1073 a couple closes that are probably noops as they were implemented
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/2fa02f31
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/2fa02f31
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/2fa02f31
Branch: refs/heads/NIFI-1073
Commit: 2fa02f31ca5d0d8e6b24a906d6883b8ad3135c06
Parents: a5501ac
Author: Tony Kurc <tr...@gmail.com>
Authored: Mon Oct 26 21:56:12 2015 -0400
Committer: Tony Kurc <tr...@gmail.com>
Committed: Mon Oct 26 21:56:12 2015 -0400
----------------------------------------------------------------------
.../cluster/manager/impl/WebClusterManager.java | 14 ++++++++------
.../org/apache/nifi/web/server/JettyServer.java | 19 ++++++++++++-------
2 files changed, 20 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi/blob/2fa02f31/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java
index bfeec7a..454d9da 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java
@@ -189,6 +189,7 @@ import org.apache.nifi.util.FormatUtils;
import org.apache.nifi.util.NiFiProperties;
import org.apache.nifi.util.ObjectHolder;
import org.apache.nifi.util.ReflectionUtils;
+import org.apache.nifi.util.file.FileUtils;
import org.apache.nifi.web.OptimisticLockingManager;
import org.apache.nifi.web.Revision;
import org.apache.nifi.web.UpdateRevision;
@@ -3310,15 +3311,16 @@ public class WebClusterManager implements HttpClusterManager, ProtocolHandler, C
completionService.submit(new Runnable() {
@Override
public void run() {
+ final OutputStream drain = new OutputStream() {
+ @Override
+ public void write(final int b) { /* drain response */ }
+ };
try {
- ((StreamingOutput) nodeResponse.getResponse().getEntity()).write(
- new OutputStream() {
- @Override
- public void write(final int b) { /* drain response */ }
- }
- );
+ ((StreamingOutput) nodeResponse.getResponse().getEntity()).write(drain);
} catch (final IOException | WebApplicationException ex) {
logger.info("Failed clearing out non-client response buffer due to: " + ex, ex);
+ } finally {
+ FileUtils.closeQuietly(drain);
}
}
}, null);
http://git-wip-us.apache.org/repos/asf/nifi/blob/2fa02f31/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java
index 99c11a8..73cf7c5 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java
@@ -38,8 +38,10 @@ import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
+
import javax.servlet.DispatcherType;
import javax.servlet.ServletContext;
+
import org.apache.nifi.NiFiServer;
import org.apache.nifi.controller.FlowSerializationException;
import org.apache.nifi.controller.FlowSynchronizationException;
@@ -49,6 +51,7 @@ import org.apache.nifi.nar.ExtensionMapping;
import org.apache.nifi.nar.NarClassLoaders;
import org.apache.nifi.services.FlowService;
import org.apache.nifi.util.NiFiProperties;
+import org.apache.nifi.util.file.FileUtils;
import org.apache.nifi.web.NiFiWebContext;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@@ -438,6 +441,7 @@ public class JettyServer implements NiFiServer {
private List<String> getWarExtensions(final File war, final String path) {
List<String> processorTypes = new ArrayList<>();
JarFile jarFile = null;
+ BufferedReader in = null;
try {
// load the jar file and attempt to find the nifi-processor entry
jarFile = new JarFile(war);
@@ -446,7 +450,7 @@ public class JettyServer implements NiFiServer {
// ensure the nifi-processor entry was found
if (jarEntry != null) {
// get an input stream for the nifi-processor configuration file
- BufferedReader in = new BufferedReader(new InputStreamReader(jarFile.getInputStream(jarEntry)));
+ in = new BufferedReader(new InputStreamReader(jarFile.getInputStream(jarEntry)));
// read in each configured type
String rawProcessorType;
@@ -461,12 +465,13 @@ public class JettyServer implements NiFiServer {
} catch (IOException ioe) {
logger.warn(String.format("Unable to inspect %s for a custom processor UI.", war));
} finally {
- try {
- // close the jar file - which closes all input streams obtained via getInputStream above
- if (jarFile != null) {
- jarFile.close();
- }
- } catch (IOException ioe) {
+ // close the jar file - which closes all input streams obtained via getInputStream above
+ if (jarFile != null) {
+ FileUtils.closeQuietly(jarFile);
+ }
+ // close the BufferedReader, this may not be strictly necessary
+ if (in != null){
+ FileUtils.closeQuietly(in);
}
}