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

ScriptTemplateView configuration option for JavaScript concurrency issues [SPR-13034] #17626

Closed
spring-issuemaster opened this issue May 15, 2015 · 4 comments
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented May 15, 2015

Sébastien Deleuze opened SPR-13034 and commented

As discussed in #16871 and on the Nashorn dev mailing list (see the reference URL), there are some concurrency issues at least with Handlebars and React, so we need to work with the Nashorn team to identify if it comes from a Nashorn bug, or if there is something on Spring side we can do to fix theses issues.


Affects: 4.2 RC1

Reference URL: http://mail.openjdk.java.net/pipermail/nashorn-dev/2015-May/004482.html

Issue Links:

  • #16871 Support JavaScript Templating

Referenced from: commits 34de167, d183bbb

0 votes, 6 watchers

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented May 25, 2015

Sébastien Deleuze commented

Last update: http://mail.openjdk.java.net/pipermail/nashorn-dev/2015-May/004593.html

Basically we are trying to see if Handlebars.compile() is thread-safe, even if that seems a strange question for a Javascript library ...

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jun 1, 2015

Sébastien Deleuze commented

See Handlebars developers feedback.

Basically, Handlerbars is not designed with concurrency in mind, but they may accept some pull requests to improve that if that means no regression for other regular users. I will try to have a look to at least identify what should be done and have an idea of the amount of work needed to fix that.

That may be also useful to be able to give some clear insights in our documentation about what are the requirements to use safely a Javascript library for server side script based template rendering.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 13, 2015

Sébastien Deleuze commented

Good news, based on this discussion, there is a ThreadLocal based solution in order to fix these concurrency issues. My tests with the script-engine-test confirms that it works, even with Handlebars (and React will be fine too)!

I am working on a commit that will make the following changes:

  • Add a isThreadBound (feel free to propose a better name if any) boolean property (default to false) to ScriptTemplateView and ScriptTemplateConfigurer that will enabled getting the engine from a ThreadLocal (it is useful to keep the non ThreadLocal based mechanism for thread safe ScriptEngine implementations or thread safe JS script libraries like Mustache)
  • If this property is true, ScriptTemplateView will get the ScriptEngine from a ThreadLocal<ScriptEngine> engineHolder field (the engine will have to be specified by its name in order to be instantiated for each thread, the setScriptEngine() setter will not be supported in when isThreadBound is enabled)

Another good news, with the latest Java 8 update 60 build 23, Underscore templating now works flawlessly !!!

I am likely to be able to push the commit tomorrow, just in time for 4.2 RC3 !

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 15, 2015

Sébastien Deleuze commented

Resolved by this commit, using the sharedEngine property name as proposed by Juergen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.