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

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

Commit 68a6149ca067076fb0f3fe0f5a78b1ded6c2f4a1 in nifi's branch 
refs/heads/NIFI-16315 from Joe Witt
[ https://gitbox.apache.org/repos/asf?p=nifi.git;h=68a6149ca06 ]

NIFI-16311 Initialize ParseSyslog parser in @OnScheduled (#11639)

CHARSET cannot change between triggers, so lazy construction in onTrigger was 
an unsynchronized check-then-act on the shared processor instance. Match 
ParseSyslog5424: build once at schedule time and publish the parser as volatile.

> ParseSyslog initializes SyslogParser unsafely under concurrent tasks
> --------------------------------------------------------------------
>
>                 Key: NIFI-16311
>                 URL: https://issues.apache.org/jira/browse/NIFI-16311
>             Project: Apache NiFi
>          Issue Type: Bug
>          Components: Extensions
>            Reporter: Joe Witt
>            Assignee: Joe Witt
>            Priority: Major
>             Fix For: 2.12.0
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> ParseSyslog keeps a SyslogParser in a non-volatile instance field and lazily 
> constructs it inside onTrigger:
>     if (parser == null || !parser.getCharsetName().equals(charsetName)) {
>         parser = new SyslogParser(Charset.forName(charsetName));
>     }
> NiFi uses a single processor instance for all concurrent tasks, so this is an 
> unsynchronized check-then-act. A second thread can observe a non-null parser 
> whose charset has not been published, or two threads can replace the field 
> while parseEvent is running.
> The Character Set property does not support Expression Language, so its value 
> cannot change between triggers. The per-trigger re-init is unnecessary.
> ParseSyslog5424 already does this correctly: it builds the parser in 
> @OnScheduled and stores it in a volatile field.
> This ticket is only that lifecycle/concurrency fix. It does not change 
> parsing, relationships, or how FlowFile content is read.
> Expected:
> - SyslogParser is created once when the processor is scheduled
> - Concurrent tasks share a safely published, immutable-for-the-run parser
> - Existing RFC3164/RFC5424 parse tests still pass
> - A TestRunner test with concurrent tasks succeeds
> Actual:
> - Parser construction races in onTrigger when Concurrent Tasks > 1



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

Reply via email to