Data corruption with Nashorn + Handlebars and concurrent requests
A. Sundararajan
sundararajan.athijegannathan at oracle.com
Tue May 26 05:50:20 UTC 2015
Oops. double negative :)
/but the compiled handlebars function may not be MT-unsafe./
should have been
"but the compiled handlebars function may not be MT-safe".
-Sundar
On Tuesday 26 May 2015 11:15 AM, A. Sundararajan wrote:
> Actually either the Handlebars.compile or the compiled function could
> be MT-unsafe. FWIW, I tried the following change to handlebars's
> render.js script:
>
> function renderHandlebars(template, model) {
>
> // Create a real Javascript Object from the model Map
> var data = {};
> for (var k in model) {
> // Convert Java Iterable and List to real Javascript arrays
> if (model[k] instanceof Java.type("java.lang.Iterable")) {
> data[k] = Java.from(model[k]);
> } else {
> data[k] = model[k];
> }
> }
> // TODO Manage compiled template cache
> var compiledTemplate = Handlebars.compile(template);
>
> // call compiled template function as synchronized
> // use Handlebars object as lock
>
> return Java.synchronized(function(data) {
> compiledTemplate(data);
> }, Handlebars);
> }
>
> With that change, it appears handlebars MT-usage seems fine [i.e., no
> exception seen]. This suggests that the Handlebars.compile itself is
> MT-safe but the compiled handlebars function may not be MT-unsafe. FYI.
More information about the nashorn-dev
mailing list