The msgpack gem (1.8.0) cannot be used inside Ractors on Ruby 4.0. Every operation - MessagePack.pack, .unpack, creating Packer/Unpacker/Factory instances - fails. This makes it impossible to use Ractors for parallel MessagePack serialization/deserialization.
#!/usr/bin/env ruby
# frozen_string_literal: true
# POC: msgpack gem 1.8.x is incompatible with Ruby 4.0 Ractors
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "msgpack", "~> 1.8"
end
require "msgpack"
puts "Ruby #{RUBY_VERSION}, msgpack #{MessagePack::VERSION}"
puts "-" * 50
tests = {
"MessagePack.pack" => -> { Ractor.new { MessagePack.pack({"a" => 1}) }.value },
"MessagePack.unpack" => -> { Ractor.new(MessagePack.pack("hi")) { |d| MessagePack.unpack(d) }.value },
"Packer.new in Ractor" => -> { Ractor.new { MessagePack::Packer.new.write("x").to_s }.value },
"Unpacker.new in Ractor" => -> { Ractor.new(MessagePack.pack(1)) { |d| u = MessagePack::Unpacker.new; u.feed(d); u.read }.value },
"Factory.new in Ractor" => -> { Ractor.new { MessagePack::Factory.new }.value },
"Send Packer to Ractor" => -> { Ractor.new(MessagePack::Packer.new) { |p| p.to_s }.value },
"Access DefaultFactory" => -> { Ractor.new { MessagePack::DefaultFactory }.value },
}
tests.each do |name, test|
print "#{name}: "
begin
test.call
puts "OK"
rescue Ractor::RemoteError => e
puts "FAILED — #{e.cause.class}: #{e.cause.message}"
rescue => e
puts "FAILED — #{e.class}: #{e.message}"
end
end
The
msgpackgem (1.8.0) cannot be used inside Ractors on Ruby 4.0. Every operation -MessagePack.pack,.unpack, creatingPacker/Unpacker/Factoryinstances - fails. This makes it impossible to use Ractors for parallel MessagePack serialization/deserialization.