Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug introduced in 2.7.3 - Context's overriddenNonMetaContextVariables member makes it unable to use it concurrently #1212

Open
sjanel opened this issue Oct 18, 2024 · 0 comments

Comments

@sjanel
Copy link

sjanel commented Oct 18, 2024

Hello,

Our code uses latest version 2.7.3 of Jinjava. There is a new field, in Context object, that makes it impossible to share across different threads, causing exceptions when the interpreter render method is called:

Caused by: com.hubspot.jinjava.interpret.InterpretException: Error rendering tag
	at com.hubspot.jinjava.tree.TagNode.render(TagNode.java:74)
	at com.hubspot.jinjava.interpret.JinjavaInterpreter.render(JinjavaInterpreter.java:363)
	at com.hubspot.jinjava.interpret.JinjavaInterpreter.render(JinjavaInterpreter.java:307)
	at ...
Caused by: java.util.ConcurrentModificationException: null
	at java.base/java.util.HashMap$HashIterator.nextNode(HashMap.java:1605)
	at java.base/java.util.HashMap$KeyIterator.next(HashMap.java:1628)
	at java.base/java.util.AbstractSet.removeAll(AbstractSet.java:175)
	at com.hubspot.jinjava.interpret.Context.removeNonMetaContextVariables(Context.java:368)
	at com.hubspot.jinjava.lib.tag.ForTag.renderForCollection(ForTag.java:292)
	at com.hubspot.jinjava.lib.tag.ForTag.interpretUnchecked(ForTag.java:155)
	at com.hubspot.jinjava.lib.tag.ForTag.interpret(ForTag.java:120)
	at com.hubspot.jinjava.lib.tag.Tag.interpretOutput(Tag.java:27)
	at com.hubspot.jinjava.tree.TagNode.render(TagNode.java:58)
	... 49 common frames omitted

I think that the field overriddenNonMetaContextVariables should allow concurrent access, otherwise client code needs to explicitly synchronize calls to render for a single top level context which holds this unique instance of this HashMap for a whole tree, which is not ideal:

this.overriddenNonMetaContextVariables =
      parent == null ? new HashSet<>() : parent.overriddenNonMetaContextVariables;

There is no issue if we revert to 2.7.2 version.

@sjanel sjanel changed the title Context's overriddenNonMetaContextVariables member makes it unable to use it concurrently Bug introduced in 2.7.3 - Context's overriddenNonMetaContextVariables member makes it unable to use it concurrently Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant