Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-17075

DatasonnetBuilder (and SimpleBuilder) does initialization in evaluate() which can cause issues under load

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.11.2
    • 3.13.0
    • camel-core
    • None
    • Unknown

    Description

      When running a simple HelloWorld app that uses datasonnet to produce the response with a high amount of requests we got a lot of exception:
      java.lang.IllegalStateException: Datasonnet expression not initialized

      Looking into DatasonnetBuilder I see that some initialisation is made inside evaluate():

          @Override
          public <T> T evaluate(Exchange exchange, Class<T> type) {
              if (expression == null) {
                  if (datasonnet == null) {
                      init(exchange.getContext());
                  }
                  if (resultType != null) {
                      Object[] properties = new Object[3];
                      properties[0] = resultType;
                      properties[1] = bodyMediaType;
                      properties[2] = outputMediaType;
                      expression = datasonnet.createExpression(text, properties);
                  } else {
                      expression = datasonnet.createExpression(text);
                  }
                  expression.init(exchange.getContext());
              }
              return expression.evaluate(exchange, type);
          }
      

      As expression is set before expression.init() is called another thread could bypass the initialisation of expression and call expression.evalutate() before expression.init() has finished. Moving this initialisation to the init method of DatasonnetBuilder would solve this problem. 
      The same problem goes for SimpleBuilder which was used as a template for implementation DatasonnetBuilder.

      Attachments

        Issue Links

          Activity

            People

              davsclaus Claus Ibsen
              henka-rl Henrik Karlsson
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: