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

fixStackOverflowErrorWhenSerializingCosmosDiagnostics #40272

Conversation

xinlian12
Copy link
Member

@xinlian12 xinlian12 commented May 20, 2024

Issue:
Within java SDK, when SDK sending the request to server, it will also spin up a separate task which will cancel the request if SDK did not get the response within the expected time. And when SDK get the response back, this task will get cancelled accordingly.

However for some rare cases, when the following combination condition happens, and overflow error can happen:

  • SDK get a response back from backend but is NotFoundException or any other type exceptions
  • The timer task suppose to be cancelled did not get cancelled properly
  • The original flow went through, and CosmosDiagnosticsContext is being set in the CosmosDiagnostics

Because Step2 is not being cancelled properly, so the expire() flow still get triggered, and due to the request failed with exception, as part of the serializing requestRecord flow, it also tried to serialize the exception. CosmosDiagnostics is one of the property in CosmosException, since there is no customized serializer on the CosmosDiagnostics, so it uses default serializer(which decides the property to be serialized based on the property and getter methods), and that is when it can hit the StackOverflowError.

com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: com.azure.cosmos.CosmosDiagnosticsContext["diagnostics"]->java.util.concurrent.ConcurrentLinkedDeque[0]->com.azure.cosmos.CosmosDiagnostics["diagnosticsContext"]->com.azure.cosmos.CosmosDiagnosticsContext["diagnostics"]->java.util.concurrent.ConcurrentLinkedDeque[0]->com.azure.cosmos.CosmosDiagnostics["diagnosticsContext"]->com.azure.cosmos.CosmosDiagnosticsContext["diagnostics"]->java.util.concurrent.ConcurrentLinkedDeque[0]->com.azure.cosmos.CosmosDiagnostics["diagnosticsContext"]->com.azure.cosmos.CosmosDiagnosticsContext["diagnostics"]->java.util.concurrent.ConcurrentLinkedDeque[0]->com.azure.cosmos.CosmosDiagnostics["diagnosticsContext"]->com.azure.cosmos.CosmosDiagnosticsContext["diagnostics"]->java.util.concurrent.ConcurrentLinkedDeque[0]->com.azure.cosmos.CosmosDiagnostics["diagnosticsContext"]->com.azure.cosmos.CosmosDiagnosticsContext["di

Fixes:

  1. In order to break the circular reference, added JsonIgnore on getDiagnosticsContext within CosmosDiagnostics
  2. In RntbdRequestRecord, changed to use error.toString when serializing the error

@azure-sdk
Copy link
Collaborator

API change check

API changes are not detected in this pull request.

Copy link
Member

@kushagraThapar kushagraThapar left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @xinlian12

@@ -90,4 +99,52 @@ public void cancelRecord() throws URISyntaxException, InterruptedException, Json
assertThat(errorStatus).isNotNull();
assertThat(errorStatus.toString()).isEqualTo(statusString);
}

@Test(groups = { "fast" })
Copy link
Member

Choose a reason for hiding this comment

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

Mixing Unit tests and fast tests is not a great idea. Now for the unit tests as well, you will initialize TestSuiteBase class for this particular class unnecessary.
Can we keep them separate?

Copy link
Member

Choose a reason for hiding this comment

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

where is the problem with initializing TestSuiteBase?

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 moved the tests into cosmosDiagnosticsTests file as part of the test is testing the serialization of the cosmos diagnostics

sdk/cosmos/azure-cosmos/CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@jeet1995 jeet1995 left a comment

Choose a reason for hiding this comment

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

LGTM - thanks!

Co-authored-by: Kushagra Thapar <kushuthapar@gmail.com>
Copy link
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

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

LGTM - Thanks!

@xinlian12
Copy link
Member Author

/azp run java - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@xinlian12
Copy link
Member Author

Tested the following tests locally:
readAllItemsWithDetailMetricsWithExplicitPageSize
readItem

@xinlian12
Copy link
Member Author

/check-enforcer override

@xinlian12
Copy link
Member Author

the failed tests does not related to the change in this PR

@xinlian12 xinlian12 merged commit 17c965a into Azure:main May 22, 2024
74 of 81 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants