diff options
| author | Luke Gruber <luke.gruber@shopify.com> | 2025-06-25 12:44:40 -0400 |
|---|---|---|
| committer | John Hawthorn <john@hawthorn.email> | 2025-07-03 13:33:10 -0700 |
| commit | cf4d37fbc079116453e69cf08ea8007d0e1c73e6 (patch) | |
| tree | 9e4420d55fcf76d73ede8c3e199d1a990bc7f575 /test/ruby | |
| parent | 4f4408e98933f65f9d5b1752c2892218f2224de3 (diff) | |
Add locks around accesses/modifications to global encodings table
This fixes segfaults and errors of the type "Encoding not found" when
using encoding-related methods and internal encoding c functions across
ractors.
Example of a possible segfault in release mode or assertion error in debug mode:
```ruby
rs = []
100.times do
rs << Ractor.new do
"abc".force_encoding(Encoding.list.shuffle.first)
end
end
while rs.any?
r, obj = Ractor.select(*rs)
rs.delete(r)
end
```
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_encoding.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/ruby/test_encoding.rb b/test/ruby/test_encoding.rb index 0ab357f53a..ae4e4a7cf7 100644 --- a/test/ruby/test_encoding.rb +++ b/test/ruby/test_encoding.rb @@ -136,4 +136,22 @@ class TestEncoding < Test::Unit::TestCase assert "[Bug #19562]" end; end + + def test_ractor_force_encoding_parallel + assert_ractor("#{<<~"begin;"}\n#{<<~'end;'}") + begin; + $-w = nil + rs = [] + 100.times do + rs << Ractor.new do + "abc".force_encoding(Encoding.list.shuffle.first) + end + end + while rs.any? + r, _obj = Ractor.select(*rs) + rs.delete(r) + end + assert rs.empty? + end; + end end |
