aws / aws-xray-sdk-dotnet

The official AWS X-Ray SDK for .NET.
Apache License 2.0
114 stars 64 forks source link

Fix race condition on static dictionaries #291

Closed udlose closed 5 months ago

udlose commented 1 year ago

Issue #282

Description of changes:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

jj22ee commented 1 year ago
Failed TestExceptionStrategy7 [6 ms]
  Error Message:
   Test method Amazon.XRay.Recorder.UnitTests.AwsXrayRecorderBuilderTests.TestExceptionStrategy7 threw exception: 
ThirdParty.LitJson.JsonException: Max allowed object depth reached while trying to export from type System.String
  Stack Trace:
      at ThirdParty.LitJson.JsonMapper.WriteValue(Object obj, JsonWriter writer, Boolean writer_is_private, Int32 depth) in /_/sdk/src/Core/ThirdParty/LitJson/JsonMapper.cs:line 715

Looks like all failing tests are due to a recursive (infinite?) loop at the WriteValue() method.

ThirdParty.LitJson.JsonException: Max allowed object depth reached while trying to export from type System.String
  Stack Trace:
      at ThirdParty.LitJson.JsonMapper.WriteValue(Object obj, JsonWriter writer, Boolean writer_is_private, Int32 depth) in /_/sdk/src/Core/ThirdParty/LitJson/JsonMapper.cs:line 715
   at ThirdParty.LitJson.JsonMapper.WriteValue(Object obj, JsonWriter writer, Boolean writer_is_private, Int32 depth) in /_/sdk/src/Core/ThirdParty/LitJson/JsonMapper.cs:line 792
   at ThirdParty.LitJson.JsonMapper.WriteValue(Object obj, JsonWriter writer, Boolean writer_is_private, Int32 depth) in /_/sdk/src/Core/ThirdParty/LitJson/JsonMapper.cs:line 850
   at ThirdParty.LitJson.JsonMapper.WriteValue(Object obj, JsonWriter writer, Boolean writer_is_private, Int32 depth) in /_/sdk/src/Core/ThirdParty/LitJson/JsonMapper.cs:line 850
   at ThirdParty.LitJson.JsonMapper.WriteValue(Object obj, JsonWriter writer, Boolean writer_is_private, Int32 depth) in /_/sdk/src/Core/ThirdParty/LitJson/JsonMapper.cs:line 783
   at ThirdParty.LitJson.JsonMapper.WriteValue(Object obj, JsonWriter writer, Boolean writer_is_private, Int32 depth) in /_/sdk/src/Core/ThirdParty/LitJson/JsonMapper.cs:line 850
   at ThirdParty.LitJson.JsonMapper.WriteValue(Object obj, JsonWriter writer, Boolean writer_is_private, Int32 depth) in /_/sdk/src/Core/ThirdParty/LitJson/JsonMapper.cs:line 850
   at ThirdParty.LitJson.JsonMapper.WriteValue(Object obj, JsonWriter writer, Boolean writer_is_private, Int32 depth) in /_/sdk/src/Core/ThirdParty/LitJson/JsonMapper.cs:line 783
   at ThirdParty.LitJson.JsonMapper.WriteValue(Object obj, JsonWriter writer, Boolean writer_is_private, Int32 depth) in /_/sdk/src/Core/ThirdParty/LitJson/JsonMapper.cs:line 850
...

Can you fix the PR, and then we will review the change.

udlose commented 1 year ago

@jj22ee my apologies. I had a PITA time trying to get it to build successfully with all of the old dependencies used for backwards compatibility. So, I wasn't able to run any of the tests. I will try to take a look this weekend.

Do you have any tips on making it a little easier to build?

jj22ee commented 1 year ago

@udlose are there any specific dependencies you are having trouble with, and what kind of build pains are you running into?

udlose commented 1 year ago

@udlose are there any specific dependencies you are having trouble with, and what kind of build pains are you running into?

@jj22ee - the .NET Framework specific dependencies are problematic as I keep only the latest version installed on my laptop. I went and installed .NET Fx 4.62 and .Net Fx 4.51 Multi Targeting Packs. There are multiple references to the compilation symbol NET45 which apparently aren't covered by installing .NET Framework 4.51. I pulled NET45 out of the project dependencies to try and get it to build but there are several references to it in the code for conditional compilation. I don't want to have to do surgery on the code just to get it to compile correctly.

Several of these dependencies are EOL anyways so they really should be removed IMO:

jj22ee commented 5 months ago

@udlose I have pushed a fix into the PR branch:

  1. There was some deleted code in your PR that I restored which does not exist in upstream LitJSON.
  2. Regarding the other synced changes, I removed them as these were incomplete since they did not incorporate the other changes in their respective commits:

To summarize, I've reduced the PR into essentially cherry-picking your upstream PR, alongside incorporating your change into the other existing code change to the copied LitJSON.