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

JsonNode.ToJsonString(JsonSerializerOptions options) Throw OutOfMemoryException #67943

Open
saber-wang opened this issue Apr 13, 2022 · 8 comments

Comments

@saber-wang
Copy link

saber-wang commented Apr 13, 2022

Description

Occasionally throw memory overflow when using JsonNode.ToJsonString

Reproduction Steps

The size of a single JsonObject is within 30000000 bytes

var transObj = new JsonObject();
transObj .ToJsonString(new JsonSerializerOptions(JsonSerializerDefaults.Web)
{
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
}))

Expected behavior

Return string

Actual behavior

Throw OutOfMemoryException

simple repros: https://github.com/saber-wang/JsonObjetcTest

Regression?

No response

Known Workarounds

No response

Configuration

Run in container
base image: mcr.microsoft.com/dotnet/runtime:6.0-alpine

memory configuration

        resources:
          limits:
            memory: 2Gi
          requests:
            memory: 256Mi
        securityContext:
          capabilities:
            add:
            - NET_ADMIN
          privileged: true

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Apr 13, 2022
@ghost
Copy link

ghost commented Apr 13, 2022

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Occasionally throw memory overflow when using JsonNode.ToJsonString

Reproduction Steps

The size of a single JsonObject is within 30000000 bytes

var transObj = new JsonObject();
transObj .ToJsonString(new JsonSerializerOptions(JsonSerializerDefaults.Web)
{
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
}))

Expected behavior

Return string

Actual behavior

Throw OutOfMemoryException

dumps: https://github.com/saber-wang/dumps

Regression?

No response

Known Workarounds

No response

Configuration

Run in container
base image: mcr.microsoft.com/dotnet/runtime:6.0-alpine

Other information

No response

Author: saber-wang
Assignees: -
Labels:

area-System.Text.Json, untriaged

Milestone: -

@saber-wang
Copy link
Author

@mangod9

@mangod9 mangod9 removed the untriaged New issue has not been triaged by the area owner label Apr 13, 2022
@mangod9 mangod9 added this to the Future milestone Apr 13, 2022
@mangod9
Copy link
Member

mangod9 commented Apr 13, 2022

hi @saber-wang, could you also please provide what memory configuration you are using for the container? If you possibly have a sample json input that might help too. thanks

@danmoseley
Copy link
Member

Please if you can share minimal, runnable code that repros this.

@saber-wang
Copy link
Author

@mangod9

         limits:
            memory: 2Gi

Sample JSON I try to print it out the next time the memory overflows

@mangod9
Copy link
Member

mangod9 commented Apr 14, 2022

Hi @saber-wang, did you mean to close this issue? If so was it resolved on your end?

@saber-wang
Copy link
Author

@mangod9 I got the JSON and tested it and found that the memory overflow is in line with expectations. However, the memory used by jsonnode is more than twice that of the original JSON. In the future, I may not use jsonnode but directly process strings

I can provide a simple repros if necessary

@saber-wang
Copy link
Author

@eiriktsarpalis eiriktsarpalis added the untriaged New issue has not been triaged by the area owner label Apr 15, 2022
@jeffschwMSFT jeffschwMSFT removed the untriaged New issue has not been triaged by the area owner label Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants