Graylog2 / Graylog2/graylog2-server
Message class should be thread-safe (ConcurrentModificationException in output)
- Dominant language
- Java
- Stars
- 8.1k
- Forks
- 1.1k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 217
Description
## Expected Behavior
I associated twice the same output to a Stream. I expected that the same message is sent to both outputs.
## Current Behavior
When I try to extract the fields from the Message I get this exception:
```
java.util.ConcurrentModificationException: null
at java.util.HashMap$HashIterator.nextNode(HashMap.java:1429) ~[?:1.8.0_72-internal]
at java.util.HashMap$EntryIterator.next(HashMap.java:1463) ~[?:1.8.0_72-internal]
at java.util.HashMap$EntryIterator.next(HashMap.java:1461) ~[?:1.8.0_72-internal]
at java.util.AbstractCollection.finishToArray(AbstractCollection.java:232) ~[?:1.8.0_72-internal]
at java.util.AbstractCollection.toArray(AbstractCollection.java:199) ~[?:1.8.0_72-internal]
at com.google.common.collect.Iterables.toArray(Iterables.java:295) ~[graylog.jar:?]
at com.google.common.collect.ImmutableMap.copyOf(ImmutableMap.java:406) ~[graylog.jar:?]
at com.google.common.collect.ImmutableMap.copyOf(ImmutableMap.java:391) ~[graylog.jar:?]
```
The problem is the behavior of ImmutableMap from Guava that fails concurrence management:
If you look at the Guava javadoc you can see:
```
/**
* Returns an immutable map containing the same entries as {@code map}. If
* {@code map} somehow contains entries with duplicate keys (for example, if
* it is a {@code SortedMap} whose comparator is not consistent with
* equals), the results of this method are undefined.
*
*
Despite the method name, this method attempts to avoid actually copying
* the data when it is safe to do so. The exact circumstances under which a
* copy will or will not be performed are undocumented and subject to change.
*
* @throws NullPointerException if any key or value in {@code map} is null
*/
public static ImmutableMap copyOf(Map map) {
...
}
```
## Possible Solution
## Steps to Reproduce (for bugs)
1. Create an input and associate it to a Stream.
2. Define two identical outputs and assign them to the Stream (the output needs to read the Message fields)
3. Send event to that input
4. Search for the exeption in the log file
## Context
## Your Environment
* Graylog Version: 2.2.3
* Elasticsearch Version:
* MongoDB Version:
* Operating System: Graylog official docker container
* Browser version:
Contributor guide
Assessment
This issue has not been assessed yet.