[ 
https://issues.apache.org/jira/browse/NIFI-15709?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18065361#comment-18065361
 ] 

ASF subversion and git services commented on NIFI-15709:
--------------------------------------------------------

Commit 9ffc2575a95616915fe012bc4a11decea3ba11b2 in nifi's branch 
refs/heads/main from Dan Chaffelson
[ https://gitbox.apache.org/repos/asf?p=nifi.git;h=9ffc2575a95 ]

NIFI-15709 Close OutputStream when schema retrieval fails in RecordWriter 
(#10997)

When writerFactory.getSchema() throws an exception, the OutputStream
opened by session.write(flowFile) was not being closed before the
continue statement. This left the FlowFile in an invalid state,
causing IllegalStateException when session.remove() was later called.

This fix ensures the OutputStream is properly closed in the error
handling path before continuing to the next message.

> ConsumeJMS RecordWriter fails with IllegalStateException when schema 
> retrieval fails
> ------------------------------------------------------------------------------------
>
>                 Key: NIFI-15709
>                 URL: https://issues.apache.org/jira/browse/NIFI-15709
>             Project: Apache NiFi
>          Issue Type: Bug
>          Components: Extensions
>    Affects Versions: 2.7.2
>            Reporter: Daniel Chaffelson
>            Priority: Minor
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> When using ConsumeJMS with Record Reader/Writer and any Output Strategy, if 
> {{writerFactory.getSchema()}} throws an exception during record processing, 
> the processor fails with:
>  
> {{java.lang.IllegalStateException: StandardFlowFileRecord[uuid=...] already 
> in use for an active callback or an OutputStream created by 
> ProcessSession.write(FlowFile) has not been closed}}
> {*}Root Cause{*}:
> In {{{}RecordWriter.java{}}}, line 130 opens an OutputStream on the FlowFile 
> via {{{}session.write(flowFile){}}}. If the subsequent 
> {{writerFactory.getSchema()}} call (line 134) throws an exception, the error 
> handling path (lines 136-139) calls {{continue}} without closing the 
> OutputStream. When {{recordCount == 0}} at line 182-183, 
> {{session.remove(flowFile)}} is called while the OutputStream is still open, 
> triggering the IllegalStateException.
> {*}Steps to Reproduce{*}:
>  # Configure ConsumeJMS with:
>  ** Record Reader: JsonTreeReader (Schema Access Strategy: Infer Schema)
>  ** Record Writer: JsonRecordSetWriter
>  ** Output Strategy: Use Wrapper (or Use Appender)
>  # Consume a JMS message where schema inference succeeds for RecordReader but 
> fails for RecordSetWriterFactory.getSchema()
>  # Processor throws IllegalStateException
> {*}Fix{*}:
> Close {{rawOut}} in the catch block before the {{continue}} statement.
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to