Skip to content

Provide way for making template compilation thread-safe #1255

@jfrantzius

Description

@jfrantzius

While compiled templates are thread-safe during rendering, it seems that template compilation itself is not.
When we run compilation concurrently for the same template, we are suddenly seeing errors during parsing like this:

:1659:13 Error: Parse error on line 21:
...         {{/content}}{{/extend}}
------------------^
Expecting 'EOF', got 'OPEN_ENDBLOCK'
    at jdk.nashorn.internal.objects.NativeError.initException(NativeError.java:137)
    at jdk.nashorn.internal.objects.NativeError.(NativeError.java:102)
    at jdk.nashorn.internal.objects.NativeError.(NativeError.java:106)
    at jdk.nashorn.internal.objects.NativeError.(NativeError.java:110)
    at jdk.nashorn.internal.objects.NativeError.constructor(NativeError.java:129)
    at jdk.nashorn.internal.scripts.Script$Recompilation$5799$67279AA$\^eval\_.L:36$L:1391$handlebars$parseError(:1659)
    at jdk.nashorn.internal.scripts.Script$Recompilation$4599$67366A$\^eval\_.L:36$L:1391$handlebars$parse(:1728)
    at jdk.nashorn.internal.scripts.Script$Recompilation$4596$37999AA$\^eval\_.L:36$L:1342$parse(:1386)
    at jdk.nashorn.internal.scripts.Script$Recompilation$4595$119328$\^eval\_.L:36$L:2733$compile-1$compileInput(:3247)
    at jdk.nashorn.internal.scripts.Script$Recompilation$4594$119696AA$\^eval\_.L:36$L:2733$compile-1$ret(:3256)
[..]

This error disappears when we isolate Handlebars instances in our threads, i.e. if we prevent concurrent template compilation on the same Handlebars instance. This comes with a performance penalty that is hard to workaround, though.

Possibly there is some parsing state global to the Handlebars instance or in the Jison generated code?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions