Skip to content

Please add documentation for thread-safety guarantees of JsonDocument (and related types) #20563

@dpaoliello

Description

@dpaoliello

Description

Looking at the documentation for JsonDocument it is not obvious if it can be safely used by multiple threads or not.

A cursory glance at the code suggests that the parsing is done up-front and, therefore, it is safe - however we tripped over the caching that is done via _lastIndexAndString (i.e., if multiple threads call GetString on an element at the same time, then they may get back the wrong value).

I want to be clear that this is a doc bug: I'm fine with having a string cache (since I assume that it provides noticeable perf benefits), but I would have liked clear guidance that JsonDocument and uses of any JsonElement from the same parent document cannot be done safely from multiple threads (without calling Clone on each element).


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions