You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JSON.dump returns NULL bytes for large HashWithIndifferentAccess objects (Linux x86_64) #951
JSON.dump() intermittently returns all NULL bytes when serializing large ActiveSupport::HashWithIndifferentAccess objects on Linux x86_64. The same code works correctly on macOS ARM with identical Ruby/gem versions.
Details
Platform: x86_64-linux
Ruby: 4.0.1
JSON: 2.19.0
ActiveSupport: 8.1.2
CPU: .25 vCPU
Memory: 1 GiB
I wasn't able to reproduce it on arm64-darwin25.
Reproduction (x86_64-linux only)
Try multiple serialization attempts with larger payloads as it's an intermittent bug, though I'm able to reproduce it consistently.
require"bundler/inline"gemfiledogem"activesupport","8.1.2"gem"json","2.19.0"endrequire'active_support/core_ext/hash'large_string="x" * (35 * 1024 * 1024);nildata={"content"=>large_string}.with_indifferent_access;nil100.timesdo |i|
json_data=JSON.dump(data)ifjson_data.getbyte(0) == 0puts"BUG: JSON.dump returned NULL bytes on attempt #{i}"puts"Size: #{json_data.bytesize} bytes"breakendend
The workaround is to convert to plain Hash before serialization using .to_h.
Thank you for looking into it! I haven't tested on Linux ARM64, but on Linux x86_64 it shows up consistently in more resource-constrained environments even with smaller payloads. It took us some time until we isolated it since in production it was showing up intermittently. Thanks!
I need to stop posting before finishing my coffee, not a red herring, I know what's going on and have a fix. Can't say for sure it's the same bug though.
Activity
byroot commentedon Mar 8, 2026
Thank you for the repro, I actually get a SEGV on Linux ARM64. Git bisect points to fff25c9
dalibor commentedon Mar 8, 2026
Thank you for looking into it! I haven't tested on Linux ARM64, but on Linux x86_64 it shows up consistently in more resource-constrained environments even with smaller payloads. It took us some time until we isolated it since in production it was showing up intermittently. Thanks!
byroot commentedon Mar 8, 2026
The SEGV was likely a red herring, I cleaned up the compilation cache and it no longer repro.
I might need to find an x86 machine because I can't effectively debug with docker. I might try virtual box or something like that.
byroot commentedon Mar 8, 2026
I need to stop posting before finishing my coffee, not a red herring, I know what's going on and have a fix. Can't say for sure it's the same bug though.
byroot commentedon Mar 8, 2026
Would you mind trying this PR: #952 ?
dalibor commentedon Mar 8, 2026
I just tested with
2.18.0and good news is that I cannot reproduce it on Linux x86_64. So, most likely related to the commit you pointed out!dalibor commentedon Mar 8, 2026
Sure, will test now with PR: #952
dalibor commentedon Mar 8, 2026
I can confirm PR: #952 fixes it. I cannot reproduce it anymore on Linux x86_64. Thank you!
byroot commentedon Mar 8, 2026
Alright,
2.19.1is out with the fix. THanks again for the repro script and for trying the fix, saved me a lot of time.dalibor commentedon Mar 8, 2026
Thank you for your time and contributions!