Henrik Karlsson created CAMEL-17075:
---------------------------------------
Summary: 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-model
Affects Versions: 3.11.2
Reporter: Henrik Karlsson
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)