Mark Payne created NIFI-15917:
---------------------------------
Summary: If an extension stores Local state and then modifies the
Map, it could lead to a corrupted stored state
Key: NIFI-15917
URL: https://issues.apache.org/jira/browse/NIFI-15917
Project: Apache NiFi
Issue Type: Bug
Components: Core Framework
Reporter: Mark Payne
Assignee: Mark Payne
If an extension does something like this:
{code:java}
private final Map<String, String> state = new ConcurrentHashMap<>();
private final AtomicLong counter = new AtomicLong(0L);
public void onTrigger(...) {
state.put("invocation", String.valueOf(counter.getAndIncrement()));
session.setState(state);
} {code}
What gets written to the state journal when the session commit is performed is
correct.
However, at some time later, when the WriteAhead Repository checkpoints, it
uses a reference to that same `state` Map rather than a defensive copy. So the
checkpoint may have a very different value than what was written to the journal.
Further, if timing is just write, it may write out the number of entries as `n`
and then write out `m` different entries. For example, if the `onTrigger`
method were to call `state.put("secondKey", "two");` while the checkpoint is
occurring, it could end up writing the fact that the map has 1 key
(`invocation`) followed by writing 2 entries (`invocation` and `secondKey`)
which would cause corruption.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)