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

fix: catch stack overflow error when parsing/preparing statements #6727

Merged

Conversation

stevenpyzhang
Copy link
Member

@stevenpyzhang stevenpyzhang commented Dec 5, 2020

Description

#5882

There were two possible places throwing the stack overflow error, while parsing/preparing.

One suggestion was to limit the Where clause size, but I don't think that's an optimal since it's possible to have a large where clause and not hit this issue. The error is being thrown when recursively trying to evaluate the boolean expression that's part of the Where clause, and the number of nested parentheses expressions is causing the deep recursion tree, but if the boolean expression was something like `Where ITM.ITEM_ID = '61151234123412345......(very long id)....12341234123412341', there wouldn't be the overflow, but the expression would have a large size.

So I just ended up catching the stack overflow error and throwing a more helpful exception.

Testing done

I Issued large where clause statement and verifying both error messages were returned.

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

@stevenpyzhang stevenpyzhang requested a review from a team as a code owner December 5, 2020 00:31
Copy link
Member

@spena spena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests to verify this?

accumulator.visit(parseTree);
return accumulator.getSources();
} catch (StackOverflowError e) {
throw new KsqlException("Error processing statement: Statement is too large to parse.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: might make sense to include the GH ticket in the error message so that users can understand which part and what to do about it (namely, make the nested parenthesis less nested)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the error messages to suggest that nested expressions could be causing the error.

@stevenpyzhang stevenpyzhang force-pushed the large-where-clause-overflow branch 2 times, most recently from 41ff83c to 5b53318 Compare December 8, 2020 21:22
@stevenpyzhang
Copy link
Member Author

For some reason, I couldn't get the QTT test to pass on the PR builder even though it passes locally, it'd fail with another stack overflow error

java.lang.StackOverflowError
	at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:239)
	at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:231)
	at java.util.ArrayList.add(ArrayList.java:462)
	at org.codehaus.janino.Java$BinaryOperation.unrollLeftAssociation(Java.java:4652)
	at org.codehaus.janino.UnitCompiler.getConstantValue2(UnitCompiler.java:5357)
	at org.codehaus.janino.UnitCompiler.access$9900(UnitCompiler.java:212)
	at org.codehaus.janino.UnitCompiler$13.visitBinaryOperation(UnitCompiler.java:5268)
	at org.codehaus.janino.Java$BinaryOperation.accept(Java.java:4665)
	at org.codehaus.janino.UnitCompiler.getConstantValue(UnitCompiler.java:5247)
	at org.codehaus.janino.UnitCompiler.getConstantValue2(UnitCompiler.java:5494)
	at org.codehaus.janino.UnitCompiler.access$9900(UnitCompiler.java:212)
	at org.codehaus.janino.UnitCompiler$13.visitBinaryOperation(UnitCompiler.java:5268)
	at org.codehaus.janino.Java$BinaryOperation.accept(Java.java:4665)
	at org.codehaus.janino.UnitCompiler.getConstantValue(UnitCompiler.java:5247)
	at org.codehaus.janino.UnitCompiler.getConstantValue2(UnitCompiler.java:5528)
	at org.codehaus.janino.UnitCompiler.access$9700(UnitCompiler.java:212)
	at org.codehaus.janino.UnitCompiler$13$1.visitParenthesizedExpression(UnitCompiler.java:5260)
	at org.codehaus.janino.Java$ParenthesizedExpression.accept(Java.java:4725)
	at org.codehaus.janino.UnitCompiler$13.visitLvalue(UnitCompiler.java:5251)
	at org.codehaus.janino.Java$Lvalue.accept(Java.java:3974)
	at org.codehaus.janino.UnitCompiler.getConstantValue(UnitCompiler.java:5247)
	at org.codehaus.janino.UnitCompiler.getConstantValue2(UnitCompiler.java:5325)
	at org.codehaus.janino.UnitCompiler.access$10100(UnitCompiler.java:212)
	at org.codehaus.janino.UnitCompiler$13.visitConditionalExpression(UnitCompiler.java:5271)
	at org.codehaus.janino.Java$ConditionalExpression.accept(Java.java:4338)
	at org.codehaus.janino.UnitCompiler.getConstantValue(UnitCompiler.java:5247)
	at org.codehaus.janino.UnitCompiler.getConstantValue2(UnitCompiler.java:5528)
	at org.codehaus.janino.UnitCompiler.access$9700(UnitCompiler.java:212)
	at org.codehaus.janino.UnitCompiler$13$1.visitParenthesizedExpression(UnitCompiler.java:5260)

So I moved the test to KsqlResourceTest

@stevenpyzhang stevenpyzhang merged commit 37371cc into confluentinc:master Dec 9, 2020
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

Successfully merging this pull request may close these issues.

3 participants