Skip to content

Fix concurrent usage of JSON::Coder#dump#874

Merged
byroot merged 1 commit intoruby:masterfrom
byroot:coder-reset-nesting
Oct 25, 2025
Merged

Fix concurrent usage of JSON::Coder#dump#874
byroot merged 1 commit intoruby:masterfrom
byroot:coder-reset-nesting

Conversation

@byroot
Copy link
Copy Markdown
Member

@byroot byroot commented Oct 25, 2025

Fix: rails/rails@9061627#r168784389

Because the depth counter is inside JSON::State it can't be used concurrently, and in case of a circular reference the counter may be left at the max value.

The depth counter should be moved outside JSON_Generator_State and into struct generate_json_data, but it's a larger refactor.

In the meantime, JSON::Coder calls State#generate_new so I changed that method so that it first copy the state on the stack.

FYI: @chaadow

Fix: rails/rails@9061627#r168784389

Because the `depth` counter is inside `JSON::State` it can't be used
concurrently, and in case of a circular reference the counter may be
left at the max value.

The depth counter should be moved outside `JSON_Generator_State` and
into `struct generate_json_data`, but it's a larger refactor.

In the meantime, `JSON::Coder` calls `State#generate_new` so I changed
that method so that it first copy the state on the stack.
@byroot byroot force-pushed the coder-reset-nesting branch from 75c7c0f to aefa671 Compare October 25, 2025 08:52
@byroot byroot merged commit 30969be into ruby:master Oct 25, 2025
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant