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

Throw stackoverflowerror in com.nr.agent.instrumentation.cassandra.CQLParser.getOperationAndTableName #827

Closed
TDtianzhenjiu opened this issue Apr 24, 2022 · 3 comments
Labels
bug Something isn't working as designed/intended

Comments

@TDtianzhenjiu
Copy link

TDtianzhenjiu commented Apr 24, 2022

Description

exceptions:
o.s.w.u.NestedServletException: Handler dispatch failed; nested exception is java.lang.StackOverflowError

stack track:

com.nr.agent.instrumentation.cassandra.CassandraUtils.metrics
com.nr.agent.instrumentation.cassandra.CQLParser.getOperationAndTableName
java.base/java.lang.String.replaceAll
java.base/java.util.regex.Matcher.replaceAll
java.base/java.util.regex.Matcher.find
java.base/java.util.regex.Matcher.search
java.base/java.util.regex.Pattern$Start.match
java.base/java.util.regex.Pattern$Slice.match
java.base/java.util.regex.Pattern$Prolog.match
java.base/java.util.regex.Pattern$LazyLoop.matchInit
java.base/java.util.regex.Pattern$GroupHead.match
java.base/java.util.regex.Pattern$Branch.match
java.base/java.util.regex.Pattern$CharProperty.match
java.base/java.util.regex.Pattern$BranchConn.match
java.base/java.util.regex.Pattern$GroupTail.match
java.base/java.util.regex.Pattern$LazyLoop.match
java.base/java.util.regex.Pattern$GroupHead.match

It seems the regular expression with some issues
The original code is here: https://github.com/newrelic/newrelic-java-agent/blob/main/instrumentation/cassandra-datastax-4.0.0/src/main/java/com/nr/agent/instrumentation/cassandra/CQLParser.java#L69
The following codes always java.lang.StackOverflowError

    String rawQuery ="/features/*.feature\\\",</strike></p><p> <strike>\\\"files.autoSave\\\": \\\"onFocusChange\\\",</strike></p><p> <strike>&nbsp;&nbsp;\\\"editor.formatOnSave\\\": true,</strike></p><p> <strike>&nbsp;&nbsp;\\\"editor.defaultFormatter\\\": \\\"esbenp.prettier-vscode\\\",</strike></p><p> <strike>&nbsp;&nbsp;\\\"window.zoomLevel\\\": 2,</strike></p><p> <strike>&nbsp;&nbsp;\\\"editor.detectIndentation\\\": false,</strike></p><p> <strike>&nbsp;&nbsp;\\\"diffEditor.wordWrap\\\": \\\"off\\\",</strike></p><p> <strike>\\\"editor.fontWeight\\\": null,</strike></p><p> <strike>\\\"javascript.updateImportsOnFileMove.enabled\\\": \\\"always\\\",</strike></p><p> <strike>\\\"git.autofetch\\\": true,</strike></p><p> <strike>\\\"[javascript]\\\": {</strike></p><p> <strike>&nbsp; &nbsp;&nbsp;\\\"editor.defaultFormatter\\\": \\\"HookyQR.beautify\\\"</strike></p><p> <strike>},</strike></p><p> <strike>\\\"prettier.bracketSpacing\\\": false,</strike></p><p> <strike>\\\"prettier.enable\\\": false,</strike></p><p> <strike>\\\"cucumberautocomplete.customParameters\\\": [</strike></p><p> <strike><br></strike></p><p> <strike>]</strike></p><p> <strike>}</strike></p></div><div><br></div><div><ul><li>Inline image</li></ul></div><div><img alt=\\\"109951167056848106.jpg\\\" width=\\\"562\\\" height=\\\"556\\\"><br></div><div>";
    rawQuery.replaceAll(COMMENT_PATTERN, "").trim();

Your Environment

java11
spring-boot 2.4.4
spring-boot-starter-data-cassandra 2.4.4

@TDtianzhenjiu TDtianzhenjiu added the bug Something isn't working as designed/intended label Apr 24, 2022
@kford-newrelic
Copy link
Contributor

@TDtianzhenjiu thanks for this detailed feedback! We've added this issue to our Triage lane for future review.

How often does this exception occur for you?

When it occurs, what's the impact - does it interrupt your application function?

Have you identified a workaround that you can use in the meantime?

@TDtianzhenjiu
Copy link
Author

Hello @kford-newrelic

  1. it occurs every time I inserted a new message to Cassandra
  2. it throws an error-> stackovererror, but usually, our application catches an exception not an error, which leads the request to fail
  3. I downgrade my newrelic version to 6.5.0, it cannot enhance datastax 4.x。 currently, we use datastax is 4.x, so it does not affect any class bytes of datastax

@GDownes
Copy link
Contributor

GDownes commented May 18, 2022

Hi @TDtianzhenjiu,
The provided example is not a valid Cassandra query is it a partial query?
I've created a Pull Request that should address your issue. It captures and ignores the exceptions raised.

The CQLParser getOperationAndTableName method used for the Cassandra 4 instrumentation is duplicated from previous Cassandra instrumentation. This Pull Request only adds exception handling for the Cassandra 4 instrumentation.

twcrone pushed a commit that referenced this issue May 23, 2022
* Capture and ignore exceptions in the CQLParser getOperationAndTableName method used by Cassandra 4.x to address #827
@GDownes GDownes closed this as completed Jun 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as designed/intended
Projects
Archived in project
Development

No branches or pull requests

3 participants