<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Apache NiFi already in use for an active callback or an InputStream created by ProcessSession.read(FlowFile) has not been closed in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Apache-NiFi-already-in-use-for-an-active-callback-or-an/m-p/372625#M241317</link>
    <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/105557"&gt;@pdesh&lt;/a&gt;&amp;nbsp;Welcome to the Cloudera Community!&lt;BR /&gt;&lt;BR /&gt;To help you get the best possible solution, I have tagged our NiFi experts&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/35454"&gt;@MattWho&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/103151"&gt;@cotopaul&lt;/a&gt;&amp;nbsp;&amp;nbsp;who may be able to assist you further.&lt;BR /&gt;&lt;BR /&gt;Please keep us updated on your post, and we hope you find a satisfactory solution to your query.&lt;/P&gt;</description>
    <pubDate>Wed, 14 Jun 2023 20:56:28 GMT</pubDate>
    <dc:creator>DianaTorres</dc:creator>
    <dc:date>2023-06-14T20:56:28Z</dc:date>
    <item>
      <title>Apache NiFi already in use for an active callback or an InputStream created by ProcessSession.read(FlowFile) has not been closed</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Apache-NiFi-already-in-use-for-an-active-callback-or-an/m-p/372615#M241309</link>
      <description>&lt;DIV&gt;I am getting following error in NiFi `ExecuteScript` processor.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;```java&lt;/DIV&gt;&lt;DIV&gt;18:07:09 UTCERROR9e1d9c5e-0188-1000-ffff-fffffbc25817&lt;/DIV&gt;&lt;DIV&gt;10.42.62.250:8080ExecuteScript[id=9e1d9c5e-0188-1000-ffff-fffffbc25817] ExecuteScript[id=9e1d9c5e-0188-1000-ffff-fffffbc25817] failed to process due to org.apache.nifi.processor.exception.ProcessException: javax.script.ScriptException: java.lang.IllegalStateException: java.lang.IllegalStateException: StandardFlowFileRecord[uuid=40d42213-2c7a-49a2-8c5d-5a7fc58bad2d,claim=StandardContentClaim [resourceClaim=StandardResourceClaim[id=1686706804350-73290, container=default, section=586], offset=6556, length=39642],offset=0,name=40d42213-2c7a-49a2-8c5d-5a7fc58bad2d,size=39642] already in use for an active callback or an InputStream created by ProcessSession.read(FlowFile) has not been closed in &amp;lt;script&amp;gt; at line number 37&lt;/DIV&gt;&lt;DIV&gt;- Caused by: javax.script.ScriptException: java.lang.IllegalStateException: java.lang.IllegalStateException: StandardFlowFileRecord[uuid=40d42213-2c7a-49a2-8c5d-5a7fc58bad2d,claim=StandardContentClaim [resourceClaim=StandardResourceClaim[id=1686706804350-73290, container=default, section=586], offset=6556, length=39642],offset=0,name=40d42213-2c7a-49a2-8c5d-5a7fc58bad2d,size=39642] already in use for an active callback or an InputStream created by ProcessSession.read(FlowFile) has not been closed in &amp;lt;script&amp;gt; at line number 37&lt;/DIV&gt;&lt;DIV&gt;- Caused by: Traceback (most recent call last):&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; File "&amp;lt;script&amp;gt;", line 37, in &amp;lt;module&amp;gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;at org.apache.nifi.controller.repository.StandardProcessSession.validateRecordState(StandardProcessSession.java:3715)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;at org.apache.nifi.controller.repository.StandardProcessSession.validateRecordState(StandardProcessSession.java:3710)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;at org.apache.nifi.controller.repository.StandardProcessSession.transfer(StandardProcessSession.java:2349)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;at jdk.internal.reflect.GeneratedMethodAccessor2736.invoke(Unknown Source)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;at java.base/java.lang.reflect.Method.invoke(Unknown Source)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;java.lang.IllegalStateException: java.lang.IllegalStateException: StandardFlowFileRecord[uuid=40d42213-2c7a-49a2-8c5d-5a7fc58bad2d,claim=StandardContentClaim [resourceClaim=StandardResourceClaim[id=1686706804350-73290, container=default, section=586], offset=6556, length=39642],offset=0,name=40d42213-2c7a-49a2-8c5d-5a7fc58bad2d,size=39642] already in use for an active callback or an InputStream created by ProcessSession.read(FlowFile) has not been closed&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;- Caused by: java.lang.IllegalStateException: StandardFlowFileRecord[uuid=40d42213-2c7a-49a2-8c5d-5a7fc58bad2d,claim=StandardContentClaim [resourceClaim=StandardResourceClaim[id=1686706804350-73290, container=default, section=586], offset=6556, length=39642],offset=0,name=40d42213-2c7a-49a2-8c5d-5a7fc58bad2d,size=39642] already in use for an active callback or an InputStream created by ProcessSession.read(FlowFile) has not been closed; rolling back session: {}&lt;/DIV&gt;&lt;DIV&gt;18:07:09 UTCERROR9e1d9c5e-0188-1000-ffff-fffffbc25817&lt;/DIV&gt;&lt;DIV&gt;10.42.62.250:8080ExecuteScript[id=9e1d9c5e-0188-1000-ffff-fffffbc25817] Processing failed: org.apache.nifi.processor.exception.ProcessException: javax.script.ScriptException: java.lang.IllegalStateException: java.lang.IllegalStateException: StandardFlowFileRecord[uuid=40d42213-2c7a-49a2-8c5d-5a7fc58bad2d,claim=StandardContentClaim [resourceClaim=StandardResourceClaim[id=1686706804350-73290, container=default, section=586], offset=6556, length=39642],offset=0,name=40d42213-2c7a-49a2-8c5d-5a7fc58bad2d,size=39642] already in use for an active callback or an InputStream created by ProcessSession.read(FlowFile) has not been closed in &amp;lt;script&amp;gt; at line number 37&lt;/DIV&gt;&lt;DIV&gt;- Caused by: javax.script.ScriptException: java.lang.IllegalStateException: java.lang.IllegalStateException: StandardFlowFileRecord[uuid=40d42213-2c7a-49a2-8c5d-5a7fc58bad2d,claim=StandardContentClaim [resourceClaim=StandardResourceClaim[id=1686706804350-73290, container=default, section=586], offset=6556, length=39642],offset=0,name=40d42213-2c7a-49a2-8c5d-5a7fc58bad2d,size=39642] already in use for an active callback or an InputStream created by ProcessSession.read(FlowFile) has not been closed in &amp;lt;script&amp;gt; at line number 37&lt;/DIV&gt;&lt;DIV&gt;- Caused by: Traceback (most recent call last):&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; File "&amp;lt;script&amp;gt;", line 37, in &amp;lt;module&amp;gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;at org.apache.nifi.controller.repository.StandardProcessSession.validateRecordState(StandardProcessSession.java:3715)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;at org.apache.nifi.controller.repository.StandardProcessSession.validateRecordState(StandardProcessSession.java:3710)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;at org.apache.nifi.controller.repository.StandardProcessSession.transfer(StandardProcessSession.java:2349)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;at jdk.internal.reflect.GeneratedMethodAccessor2736.invoke(Unknown Source)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;at java.base/java.lang.reflect.Method.invoke(Unknown Source)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;java.lang.IllegalStateException: java.lang.IllegalStateException: StandardFlowFileRecord[uuid=40d42213-2c7a-49a2-8c5d-5a7fc58bad2d,claim=StandardContentClaim [resourceClaim=StandardResourceClaim[id=1686706804350-73290, container=default, section=586], offset=6556, length=39642],offset=0,name=40d42213-2c7a-49a2-8c5d-5a7fc58bad2d,size=39642] already in use for an active callback or an InputStream created by ProcessSession.read(FlowFile) has not been closed&lt;/DIV&gt;&lt;DIV&gt;```&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I am trying to run following script in NiFi `ExecuteScript` processor&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;```&lt;/DIV&gt;&lt;DIV&gt;import xml.etree.ElementTree as ET&lt;/DIV&gt;&lt;DIV&gt;import os&lt;/DIV&gt;&lt;DIV&gt;import java.io&lt;/DIV&gt;&lt;DIV&gt;from org.apache.commons.io import IOUtils&lt;/DIV&gt;&lt;DIV&gt;from java.nio.charset import StandardCharsets&lt;/DIV&gt;&lt;DIV&gt;def find_pattern_in_xml(file_path, target_string):&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; tree = ET.ElementTree(ET.fromstring(file_path))&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; root = tree.getroot()&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; found_elements = []&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; # Iterate through all elements in the XML tree&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; for element in root.iter():&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Check if the target string is present in the element text&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if target_string in element.text:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; found_elements.append(element)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; return found_elements&lt;/DIV&gt;&lt;DIV&gt;flowFile = session.get()&lt;/DIV&gt;&lt;DIV&gt;if flowFile is not None:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; try:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; stream_content = session.read(flowFile)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; text_content = IOUtils.toString(stream_content, StandardCharsets.UTF_8)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # flowfile_path = flowFile.getAttribute('sourceFileName')&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; target_string = "~Indv"&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; found_elements = find_pattern_in_xml(flowfile_path, target_string)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Print the found elements&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for element in found_elements:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; session.remove(flowFile)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(element.tag, element.text)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; except Exception as e:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Log the error and route the flowfile to failure&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; log.error("Error processing flowfile"+ str(e))&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; session.transfer(flowFile, REL_FAILURE)&lt;/DIV&gt;&lt;DIV&gt;session.commit()&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;```&lt;/DIV&gt;</description>
      <pubDate>Wed, 14 Jun 2023 18:24:05 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Apache-NiFi-already-in-use-for-an-active-callback-or-an/m-p/372615#M241309</guid>
      <dc:creator>pdesh</dc:creator>
      <dc:date>2023-06-14T18:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: Apache NiFi already in use for an active callback or an InputStream created by ProcessSession.read(FlowFile) has not been closed</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Apache-NiFi-already-in-use-for-an-active-callback-or-an/m-p/372625#M241317</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/105557"&gt;@pdesh&lt;/a&gt;&amp;nbsp;Welcome to the Cloudera Community!&lt;BR /&gt;&lt;BR /&gt;To help you get the best possible solution, I have tagged our NiFi experts&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/35454"&gt;@MattWho&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/103151"&gt;@cotopaul&lt;/a&gt;&amp;nbsp;&amp;nbsp;who may be able to assist you further.&lt;BR /&gt;&lt;BR /&gt;Please keep us updated on your post, and we hope you find a satisfactory solution to your query.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 20:56:28 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Apache-NiFi-already-in-use-for-an-active-callback-or-an/m-p/372625#M241317</guid>
      <dc:creator>DianaTorres</dc:creator>
      <dc:date>2023-06-14T20:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: Apache NiFi already in use for an active callback or an InputStream created by ProcessSession.read(FlowFile) has not been closed</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Apache-NiFi-already-in-use-for-an-active-callback-or-an/m-p/373114#M241491</link>
      <description>&lt;P&gt;This is likely what's generating the error... You're saying remove the Flow file in a loop and should only be done once.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for element in found_elements:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; session.remove(flowFile)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(element.tag, element.text)&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2023 00:56:28 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Apache-NiFi-already-in-use-for-an-active-callback-or-an/m-p/373114#M241491</guid>
      <dc:creator>joseomjr</dc:creator>
      <dc:date>2023-06-23T00:56:28Z</dc:date>
    </item>
  </channel>
</rss>

