Skip to content

ScriptedConfiguration publishes the Groovy engine before its customizer has run #148

Closed

Description

@vharseko

Found in the review of #132; the bug predates that PR.

What happens

ScriptedConfiguration.getGroovyScriptEngine() stores the new engine in the groovyScriptEngine field (ScriptedConfiguration.java:797) before initializeCustomizer() runs (:800). It has to: getCustomizerClass() (:727) calls getGroovyScriptEngine() again on the same thread. That has two consequences:

  1. The customizer fails. initializeCustomizer() (:811) wraps the exception in a ConnectorException and rethrows it, but nothing clears the field. Every later caller takes the fast path at :786 and runs scripts on an engine whose customizer never ran. In the scripted REST connector, ScriptedRESTConfiguration.getHttpClient then fails with an NPE on initClosure (ScriptedRESTConfiguration.groovy:218), which the customizer was supposed to set, and the original customizer error is lost.
  2. Another thread arrives during customization. A thread that reads the field at :786 while the first thread is still inside the customizer gets the engine without its customizations.

Making the field volatile (#132) does not change either case, because the field is still published before the customization is done.

Expected

Other threads only ever see a customized engine. If the customizer fails, the next call retries the customization instead of silently using an uncustomized engine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugconcurrencyconnector:groovy

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions