Re: Deadlock issue
Jacopo Cappellato <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
On Apr 20, 2012, at 3:31 PM, Daniel López wrote: > Hi, > > Of course, keep us informed. Glad to be of help. > Thank you, I will keep you informed. For reference I am forwarding you the commit log I did for OFBiz: Begin forwarded message: > From: [email protected] > Subject: svn commit: r1328356 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/GroovyUtil.java > Date: April 20, 2012 2:53:35 PM GMT+02:00 > To: [email protected] > Reply-To: [email protected] > > Author: jacopoc > Date: Fri Apr 20 12:53:35 2012 > New Revision: 1328356 > > URL: http://svn.apache.org/viewvc?rev=1328356&view=rev > Log: > The cache of parsed Groovy scripts was not thread safe; this issue, in instances with several concurrent threads running the same script the first time (i.e. not cached) could cause the same script to be parsed multiple times and then added to the cache (overriding the previous value); this event was causing the clearing of caches in Freemarker; because of a bug in Freemarker [*] this could cause a deadlock. > The issue is present on all versions of Freemarker but it is less frequent on latest version because of the refactoring of caches happened after release 2.3.10. > > [*] https://sourceforge.net/tracker/?func=detail&aid=3519805&group_id=794&atid=100794 > > Modified: > ofbiz/trunk/framework/base/src/org/ofbiz/base/util/GroovyUtil.java > > Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/GroovyUtil.java > URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/GroovyUtil.java?rev=1328356&r1=1328355&r2=1328356&view=diff > ============================================================================== > --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/GroovyUtil.java (original) > +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/GroovyUtil.java Fri Apr 20 12:53:35 2012 > @@ -127,10 +127,17 @@ public class GroovyUtil { > } else { > scriptClass = parseClass(scriptUrl.openStream(), location); > } > - if (Debug.verboseOn()) { > - Debug.logVerbose("Caching Groovy script at: " + location, module); > + synchronized (parsedScripts) { > + Class<?> scriptClassCached = parsedScripts.get(location); > + if (scriptClassCached == null) { > + if (Debug.verboseOn()) { > + Debug.logVerbose("Caching Groovy script at: " + location, module); > + } > + parsedScripts.put(location, scriptClass); > + } else { > + scriptClass = scriptClassCached; > + } > } > - parsedScripts.put(location, scriptClass); > } > return scriptClass; > } catch (Exception e) { > @@ -177,10 +184,18 @@ public class GroovyUtil { > Class<?> scriptClass = parsedScripts.get(script); > if (scriptClass == null) { > scriptClass = loadClass(script); > - if (Debug.verboseOn()) Debug.logVerbose("Caching Groovy script: " + script, module); > - parsedScripts.put(script, scriptClass); > + synchronized (parsedScripts) { > + Class<?> scriptClassCached = parsedScripts.get(script); > + if (scriptClassCached == null) { > + if (Debug.verboseOn()) { > + Debug.logVerbose("Caching Groovy script: " + script, module); > + } > + parsedScripts.put(script, scriptClass); > + } else { > + scriptClass = scriptClassCached; > + } > + } > } > - > return InvokerHelper.createScript(scriptClass, getBinding(context)).run(); > } catch (CompilationFailedException e) { > String errMsg = "Error loading Groovy script [" + script + "]: " + e.toString(); > > ------------------------------------------------------------------------------ For Developers, A Lot Can Happen In A Second. Boundary is the first to Know...and Tell You. Monitor Your Applications in Ultra-Fine Resolution. Try it FREE! http://p.sf.net/sfu/Boundary-d2dvs2