When executing multiple (same) native queries against MongoDB (using createNativeQuery), following error happens easily:
java.lang.IllegalArgumentException: Cannot peek beyond the bottom of the stack at org.parboiled.MatcherContext.runMatcher(MatcherContext.java:367) ~[parboiled-core-1.1.8.jar:1.1.8] at org.parboiled.matchers.SequenceMatcher.match(SequenceMatcher.java:46) ~[parboiled-core-1.1.8.jar:1.1.8] at org.parboiled.parserunners.BasicParseRunner.match(BasicParseRunner.java:77) ~[parboiled-core-1.1.8.jar:1.1.8]
Parboiled parsers are *not* thread safe - https://github.com/sirthias/parboiled/wiki/Thread-Safety
Yet the MongoDialect uses shared, static parser for native queries - https://github.com/hibernate/hibernate-ogm/blob/master/mongodb/src/main/java/org/hibernate/ogm/datastore/mongodb/MongoDBDialect.java :
{code:java} private static final NativeQueryParser NATIVE_QUERY_PARSER = Parboiled.createParser( NativeQueryParser.class ); {code}
The access to this property is not synchronized.
Wrapping query execution (in the app) in synchronized (globalLock) mitigates this issue instantly and completely - but it hurts performance a lot as no queries can be executed in parallel.
|
|