Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrency issue on the toObject function #40

Open
minhtran-q opened this issue Jan 27, 2022 · 0 comments
Open

Concurrency issue on the toObject function #40

minhtran-q opened this issue Jan 27, 2022 · 0 comments

Comments

@minhtran-q
Copy link

I have encountered a concurrent problem when using the toObject function. I spent a few hours checking the source code. And I realize a potential concurrency issue in class ToJSONObjectFunctionExtension.

JSONParser is created as a global variable in class ToJSONObjectFunctionExtension. When executing the execute(Object data, State state) function, the parse(data.toString()) function will be called with the input parameter. Everything looks good

    private static final JSONParser jsonParser = new JSONParser(JSONParser.DEFAULT_PERMISSIVE_MODE);  //global variable

    //...
    
    @Override
    protected Object execute(Object data, State state) {
        Object returnValue = null;
        try {
            returnValue = jsonParser.parse(data.toString());
        } catch (ParseException e) {
            log.error(siddhiQueryContext.getSiddhiAppContext().getName() + ":" + siddhiQueryContext.getName() +
                    ": Cannot parse the given string into JSON. Hence returning null");
        }
        return returnValue;
    }

Unfortunately, If you check function parse(String input) of class JSONParser, you will see the input parameter will be set to a global variable in class JSONParserString. In the case of multiple threads execution function execute(Object data, State state) at the same time, it will cause the concurrency issue.

Version: siddhi-execution-json 2.0.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant