You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Claus Ibsen (Jira)" <ji...@apache.org> on 2021/10/14 05:51:00 UTC

[jira] [Assigned] (CAMEL-17075) DatasonnetBuilder (and SimpleBuilder) does initialization in evaluate() which can cause issues under load

     [ https://issues.apache.org/jira/browse/CAMEL-17075?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claus Ibsen reassigned CAMEL-17075:
-----------------------------------

    Assignee: Claus Ibsen

> DatasonnetBuilder (and SimpleBuilder) does initialization in evaluate() which can cause issues under load
> ---------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-17075
>                 URL: https://issues.apache.org/jira/browse/CAMEL-17075
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 3.11.2
>            Reporter: Henrik Karlsson
>            Assignee: Claus Ibsen
>            Priority: Major
>             Fix For: 3.13.0
>
>
> 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():
> {code:java}
>     @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);
>     }
> {code}
> 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.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)