[ https://issues.apache.org/jira/browse/TINKERPOP-1830?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16248449#comment-16248449 ]
ASF GitHub Bot commented on TINKERPOP-1830: ------------------------------------------- Github user spmallette commented on a diff in the pull request: https://github.com/apache/tinkerpop/pull/745#discussion_r150381086 --- Diff: tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIndex.java --- @@ -48,17 +48,18 @@ public TinkerIndex(final TinkerGraph graph, final Class<T> indexClass) { protected void put(final String key, final Object value, final T element) { Map<Object, Set<T>> keyMap = this.index.get(key); - if (keyMap == null) { - keyMap = new ConcurrentHashMap<>(); - this.index.put(key, keyMap); + if (null == keyMap) { + Map<Object, Set<T>> tmpMap = new ConcurrentHashMap<>(); + this.index.putIfAbsent(key, tmpMap); + keyMap = this.index.get(key); } Set<T> objects = keyMap.get(value); if (null == objects) { - objects = new HashSet<>(); - keyMap.put(value, objects); + Set<T> tmpObjects = ConcurrentHashMap.newKeySet(); --- End diff -- can you add a `final` here please? > Race condition in Tinkergraph index creation > --------------------------------------------- > > Key: TINKERPOP-1830 > URL: https://issues.apache.org/jira/browse/TINKERPOP-1830 > Project: TinkerPop > Issue Type: Bug > Components: tinkergraph > Affects Versions: 3.3.0, 3.2.6 > Reporter: Michael Pollmeier > Priority: Minor > Fix For: 3.2.7, 3.3.1 > > > My colleage Fabian Yamaguchi <f...@shiftleft.io> discovered a race condition > in tinkergraph's index creation. He fixed it by simply replacing > `parallelStream` with `stream`. Quoting his analysis: > > So, reading the code, you see that this.put is called in parallel, but that > > method seems to contain a race as get is called on the index, checked for > > null, and a subsequent write is performed. It still seems like using stream > > here fixes the problem we've been seeing, and the performance hit is not > > significant. -- This message was sent by Atlassian JIRA (v6.4.14#64029)