Diagnosing Ruby Ractor Isolation Errors When Passing Objects Between Actors
Why Ruby Ractor raises isolation or moved errors, how to check shareability, and when to stop forcing shared state.
27 Aug 2026, 01:39 UTC

You send an object from one Ractor to another, and Ruby raises Ractor::MovedError or an isolation error instead of delivering the message. The sender may also lose access to the object after Ractor.send or Ractor.yield.
Useful takeaway: Ractor isolates mutable state by default. Only objects Ruby considers shareable can cross actor boundaries, and a moved object is no longer usable in the sender. Before changing code, confirm the object's shareability, then either freeze and mark it shareable, rebuild it inside the receiver, or stop sharing it entirely.
What the error means
A Ractor is Ruby's actor-like concurrency primitive. Each Ractor has its own lock and heap, so two Ractors cannot safely mutate the same object at the same time. Ruby enforces this with shareability: an object is shareable if it is immutable or explicitly marked safe for cross-actor access. When you pass a non-shareable object, Ruby raises an isolation error. When you pass an object that has already been moved into another Ractor, the sender gets Ractor::MovedError if it tries to use the object again.
Verify the runtime first. Ractor is available in Ruby 3.x, but behavior can differ between patchlevels.
Recognizable condition and likely causes
| Symptom | Likely cause | First check |
|---|---|---|
Ractor::MovedError when the sender uses the object after sending | The object was moved, not copied; ownership transferred to the receiver | Check whether the sender still references the payload after Ractor.send or Ractor.yield |
| Isolation error when the receiver tries to use the object | The payload is not shareable | Call Ractor.shareable?(payload) before sending |
| Frozen strings and symbols work; custom objects fail | The custom class is not marked shareable | Inspect the class and its instance variables |
| Errors only with IO objects, threads, procs with bindings, or extension-library objects | The object cannot be frozen or marked shareable | Do not force sharing; redesign the message |
Ordered checks
- Confirm Ractor is available. Run in a terminal:
Expected: a Ruby 3.x version line andruby -v ruby -e 'puts defined?(Ractor)'constant(orRactor) from the second command. If it printsnil, Ractor is not available in this build. Permissions: none. Risk: none. - Check payload shareability before sending.
Run this in a script or REPL. Permissions: none. Risk: none for the check itself.payload = 'some data' puts Ractor.shareable?(payload) # false for an ordinary unfrozen string - Check whether the object is deeply frozen.
Permissions: none. Risk: none for inspection.def deeply_frozen?(obj) return false unless obj.frozen? case obj when Array, Hash then obj.each.all? { |k, v| deeply_frozen?(k) && deeply_frozen?(v) } else true end end - Check whether the sender still references the object after a send or yield.
Permissions: none. Risk: accessing a moved object raisesr = Ractor.new do received = Ractor.receive puts received end r.send(payload) # Do not use payload here if it was movedRactor::MovedError.
Fixes tied to findings
1. Simple object graph: freeze and mark shareable
If the payload is a plain string, array, or hash that you own, freeze it deeply and mark it shareable:
payload = ['a', 'b', 'c']
payload.each(&:freeze)
payload.freeze
Ractor.make_shareable(payload)
puts Ractor.shareable?(payload) # expect true in Ruby 3.x
Then send it. Limitation: Ractor.make_shareable mutates the object and is irreversible for that instance. Do not call it on objects owned by libraries that mutate them after construction.
2. Complex or foreign object graph: rebuild inside the receiver
Send only the data needed to reconstruct the object, then build it in the receiving Ractor:
sender = Ractor.new do
Ractor.yield({ id: 42, name: 'example' })
end
config = sender.take
receiver = Ractor.new(config) do |cfg|
MyService.new(cfg[:id], cfg[:name])
end
3. Coordination without shared mutable state
Use Ractor.select to wait on multiple Ractors instead of sharing a mutable flag or queue:
r1 = Ractor.new { Ractor.yield :one }
r2 = Ractor.new { Ractor.yield :two }
result, _ractor = Ractor.select(r1, r2)
4. Unshareable objects: do not force sharing
If the graph contains IO objects, threads, procs with bindings, or C-extension objects that cannot be frozen, keep the work in one Ractor and pass only primitive identifiers or messages.
Escalation criteria
- The object graph contains IO objects, threads, procs with bindings, or extension-library objects that cannot be frozen.
- A documented shareable type raises an isolation error unexpectedly.
- Deep freezing is too expensive for the object size or breaks a library that mutates objects after construction.
In these cases, redesign to message-copy or isolate the work in a single Ractor. Escalate to a maintainer only if a documented shareable type raises unexpectedly after you have verified the Ruby version.
Minimal verification script
Save this as ractor_share_check.rb and run ruby ractor_share_check.rb. It sends a frozen shareable string and an unfrozen string between Ractors. Permissions: none. Risk: the script intentionally triggers errors and rescues them.
require 'ractor'
shareable = 'hello'.freeze
Ractor.make_shareable(shareable)
unshareable = 'world'
r = Ractor.new do
received = Ractor.receive
Ractor.shareable?(received)
end
begin
r.send(shareable)
puts "shareable sent: #{r.take}"
rescue => e
puts "shareable failed: #{e.class}"
end
r2 = Ractor.new do
received = Ractor.receive
Ractor.shareable?(received)
end
begin
r2.send(unshareable)
puts "unshareable sent: #{r2.take}"
rescue => e
puts "unshareable failed: #{e.class}"
end
Check the result: the shareable string should pass without an isolation error, and the unfrozen string should raise before or at receipt. If both behave the same way, verify your Ruby patchlevel; do not assume the behavior matches another release.
Limitations
- Ractor shareability rules can change between Ruby patchlevels; verify against the exact runtime in use.
- Deep freezing large object graphs is expensive and can break libraries that mutate objects after construction.
- Ractor does not guarantee faster CPU throughput for GIL-bound C extensions; many extensions release the GIL inconsistently.
Practical check after applying a fix
Run the same minimal script with your production object types. Confirm Ractor.shareable?(obj) returns true before sending and that no Ractor::MovedError or isolation error occurs when the receiver takes the message.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.