Actions
Bug #19375
closedFile objects are currently shareable, as are other extension objects that shouldn't be.
    Bug #19375:
    File objects are currently shareable, as are other extension objects that shouldn't be.
  
Description
I don't know the internals of file.c but I don't think files are thread-safe.
        
           Updated by luke-gru (Luke Gruber) almost 3 years ago
          Updated by luke-gru (Luke Gruber) almost 3 years ago
          
          
        
        
      
      - Subject changed from File objects are currently shareable to File objects are currently shareable, as are other extension objects that shouldn't be.
The issue is with Ractor.make_shareable
The same issue occurs with Dir, Tempfile, IO objects, the ENV hash. StringIO and CSV have this problem too. Sockets I think have the issue.
For example, the issue with StringIO is that it needs an initialize_clone method that dup's the string. The underlying issue, though, is that it's a TypedData and doesn't
store its internals in instance variables to be checked by the sharing logic.
require 'stringio'
str = "string".dup
stringio = StringIO.new(str)
rs = 100.times.map do
  Ractor.new do
    strio = receive
    p strio.string.object_id
    p strio.string.frozen?
  end
end
p stringio.string.object_id
rs.each do |r|
  r.send(stringio)
end
rs.each(&:take)
        
           Updated by luke-gru (Luke Gruber) almost 2 years ago
          Updated by luke-gru (Luke Gruber) almost 2 years ago
          
          
        
        
      
      This has been fixed by @ko1 (Koichi Sasada) in 7718e9588b4d7d83c8f9a89dce10b06b9f97bddb, it can be closed now. It could possibly use a backport, but I'll leave that up to you guys. Thank you!
        
           Updated by jeremyevans0 (Jeremy Evans) almost 2 years ago
          Updated by jeremyevans0 (Jeremy Evans) almost 2 years ago
          
          
        
        
      
      - Status changed from Open to Closed
Actions