Is JSON::Coder intended to be thread safe ?
还没有人认领这个 Issue。
评估
调研方向
从 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
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/json 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 55/100
-
难度 4/5 3-5 天 新手友好度 48/100
-
Output formatting differences between jRuby 10.0.0.1 and Ruby 3.4 when converting Float to JSON. 未关闭jruby
-
jruby
-
new feature
难度 5/5 一周以上 新手友好度 25/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
simp/pupmod-simp-simp#395 ·
-
难度 2/5 1-3 小时 新手友好度 80/100
simp/pupmod-simp-rsyslog#219 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
simp/pupmod-simp-pupmod#256 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
simp/pupmod-simp-sudo#150 ·
-
难度 1/5 1 小时以内 新手友好度 90/100