Uploaded image for project: 'Hibernate OGM'
  1. OGM-1544

MongoDBDialect uses shared Parboiled parser across multiple threads, while the parser is NOT thread safe

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 5.4.0.Final
    • Fix Version/s: 5.4.1.Final
    • Component/s: mongodb
    • Labels:
      None
    • Environment:
      Hibernate 5.3.7
      OpenJDK 11
      Spring Boot 2.1
      MongoDB 3.4

      Description

      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:

      	private static final NativeQueryParser NATIVE_QUERY_PARSER = Parboiled.createParser( NativeQueryParser.class );
      

      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.

        Attachments

          Issue links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: