Skip to content

JsonNode.ToJsonString(JsonSerializerOptions options) Throw OutOfMemoryException #67943

Open

Description

@saber-wang

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

Activity

  1. ghost added
    untriaged
    on Apr 13, 2022
  2. saber-wang commented on Apr 13, 2022

    @saber-wang
    Author
  3. removed
    untriaged
    on Apr 13, 2022
  4. added this to the Future milestone on Apr 13, 2022
  5. mangod9 commented on Apr 13, 2022

    @mangod9
    Member

    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

  6. danmoseley commented on Apr 13, 2022

    @danmoseley
    Contributor

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

  7. saber-wang commented on Apr 13, 2022

    @saber-wang
    Author

    @mangod9

             limits:
                memory: 2Gi
    

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

  8. mangod9 commented on Apr 14, 2022

    @mangod9
    Member

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

  9. saber-wang commented on Apr 15, 2022

    @saber-wang
    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

  10. added
    untriaged
    on Apr 15, 2022
  11. removed
    untriaged
    on Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions