Make Addrinfo objects Ractor shareable

Allow Addrinfo objects to be shared among Ractors.  Addrinfo objects are
already immutable, so I think it's safe for us to tag them as
RUBY_TYPED_FROZEN_SHAREABLE shareable too.
This commit is contained in:
Aaron Patterson 2025-05-20 16:37:51 -07:00 committed by Aaron Patterson
parent b08e20d34a
commit 1c66124273
Notes: git 2025-05-21 01:04:50 +00:00
2 changed files with 7 additions and 0 deletions

View File

@ -1211,6 +1211,7 @@ addrinfo_memsize(const void *ptr)
static const rb_data_type_t addrinfo_type = {
"socket/addrinfo",
{addrinfo_mark, addrinfo_free, addrinfo_memsize,},
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_FROZEN_SHAREABLE,
};
static VALUE

View File

@ -360,6 +360,12 @@ class TestSocketAddrinfo < Test::Unit::TestCase
assert_raise(Socket::ResolutionError) { Addrinfo.tcp("0.0.0.0", 4649).family_addrinfo("::1", 80) }
end
def test_ractor_shareable
assert_ractor(<<~'RUBY', require: 'socket', timeout: 60)
Ractor.make_shareable Addrinfo.new "\x10\x02\x14\xE9\xE0\x00\x00\xFB\x00\x00\x00\x00\x00\x00\x00\x00".b
RUBY
end
def random_port
# IANA suggests dynamic port for 49152 to 65535
# http://www.iana.org/assignments/port-numbers