Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Is JSON::Coder intended to be thread safe ?

未关闭
#1,064 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
38/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
json, ruby
领域
backend

调研方向

从 activesupport/lib/active_support/json/encoding.rb 中 JSON::Coder 的共享创建和复用位置开始,然后检查 JSON::Coder#dump 和 #generate 在 JRuby 上的并发行为。如果提供了报告中的多线程复现,则使用它来确认竞争条件;当线程安全契约确定下来,并且该行为已记录或由回归测试覆盖时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

In JRuby we hit a race condition: ActiveSupport uses a single shared JSON::Coder
instance and calls #dump on it from multiple threads.

ActiveSupport creates one shared Coder:
https://github.com/rails/rails/blob/v8.1.3.1/activesupport/lib/active_support/json/encoding.rb#L152

…and reuses it on every encode:
https://github.com/rails/rails/blob/v8.1.3.1/activesupport/lib/active_support/json/encoding.rb#L188

The error we got, on a flat object was

JSON::NestingError: nesting of 100 is too deep. Did you try to serialize objects with circular references?

Question: is a single JSON::Coder instance intended to be safe to call
concurrently from multiple threads (i.e. is #dump/#generate on one Coder
intended to be thread-safe)?

Versions: json 2.21.2 (java), JRuby 10.0.5.0, activesupport 8.1.3.1.

I have a small threaded reproduction I can add if useful.

主要语言
Ruby
星标
782
派生
383
平均合并
1 天 18 小时
30 天内合并 PR
10

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ruby/json 的其他 Issue

查看 ruby/json 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。