[ruby-core:121121] [Ruby master Bug#21149] Strange behavior of ObjectSpace.each_object after Ractor.new

Issue #21149 has been reported by wanabe (_ wanabe). ---------------------------------------- Bug #21149: Strange behavior of ObjectSpace.each_object after Ractor.new https://bugs.ruby-lang.org/issues/21149 * Author: wanabe (_ wanabe) * Status: Open * ruby -v: ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- I found the strange behavior of `ObjectSpace.each_object`. It misses some objects after `Ractor.new`. ``` $ ruby -ve 'class Foo; end; foo = Foo.new; Ractor.new do buz = Foo.new end.take; bar = Foo.new; p [ObjectSpace.each_object(Foo).to_a, foo.class, bar.class]' ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux] -e:1: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues. [[], Foo, Foo] ``` Of course it works well without `Ractor.new`. ``` $ ruby -ve 'class Foo; end; foo = Foo.new; bar = Foo.new; p [ObjectSpace.each_object(Foo).to_a, foo.class, bar.class]' ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux] [[#<Foo:0x00007fa84f4b26d0>, #<Foo:0x00007fa84f4b27c0>], Foo, Foo] ``` -- https://bugs.ruby-lang.org/

Issue #21149 has been updated by nobu (Nobuyoshi Nakada). Interesting. It seems irrelevant what is done in the new Ractor. Even if the block is empty, the result is same. ---------------------------------------- Bug #21149: Strange behavior of ObjectSpace.each_object after Ractor.new https://bugs.ruby-lang.org/issues/21149#change-112045 * Author: wanabe (_ wanabe) * Status: Open * ruby -v: ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- I found the strange behavior of `ObjectSpace.each_object`. It misses some objects after `Ractor.new`. ``` $ ruby -ve 'class Foo; end; foo = Foo.new; Ractor.new do buz = Foo.new end.take; bar = Foo.new; p [ObjectSpace.each_object(Foo).to_a, foo.class, bar.class]' ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux] -e:1: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues. [[], Foo, Foo] ``` Of course it works well without `Ractor.new`. ``` $ ruby -ve 'class Foo; end; foo = Foo.new; bar = Foo.new; p [ObjectSpace.each_object(Foo).to_a, foo.class, bar.class]' ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux] [[#<Foo:0x00007fa84f4b26d0>, #<Foo:0x00007fa84f4b27c0>], Foo, Foo] ``` -- https://bugs.ruby-lang.org/

Issue #21149 has been updated by luke-gru (Luke Gruber). Yes, this is a known bug. Currently, objects don't record which ractor they belong to. Therefore, after you start new Ractor Ruby can't know if it should yield an unshareable object to `ObjectSpace.each_object`, because it would violate Ractor safety if it did. You can see that shareable objects (like if you froze it) are yielded. You can see the code here: https://github.com/ruby/ruby/blob/master/gc.c#L1526-L1528 From what I remember, this is documented somewhere but I could be wrong. If it's not documented, it should be. ---------------------------------------- Bug #21149: Strange behavior of ObjectSpace.each_object after Ractor.new https://bugs.ruby-lang.org/issues/21149#change-112052 * Author: wanabe (_ wanabe) * Status: Open * ruby -v: ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- I found the strange behavior of `ObjectSpace.each_object`. It misses some objects after `Ractor.new`. ``` $ ruby -ve 'class Foo; end; foo = Foo.new; Ractor.new do buz = Foo.new end.take; bar = Foo.new; p [ObjectSpace.each_object(Foo).to_a, foo.class, bar.class]' ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux] -e:1: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues. [[], Foo, Foo] ``` Of course it works well without `Ractor.new`. ``` $ ruby -ve 'class Foo; end; foo = Foo.new; bar = Foo.new; p [ObjectSpace.each_object(Foo).to_a, foo.class, bar.class]' ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux] [[#<Foo:0x00007fa84f4b26d0>, #<Foo:0x00007fa84f4b27c0>], Foo, Foo] ``` -- https://bugs.ruby-lang.org/

Issue #21149 has been updated by wanabe (_ wanabe). Status changed from Open to Rejected Thank you. I forgot to search existing issues before opening the ticket. Now I can see many related tickets: - [Feature #17270] ObjectSpace.each_object should be restricted on multi-Ractors - [Bug #17360] Objects disappear from ObjectSpace after using Ractor - [Bug #19387] Issue with ObjectSpace.each_objects not returning objects after starting a ractor I will reject this #21149 as duplicated. ---------------------------------------- Bug #21149: Strange behavior of ObjectSpace.each_object after Ractor.new https://bugs.ruby-lang.org/issues/21149#change-112054 * Author: wanabe (_ wanabe) * Status: Rejected * ruby -v: ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- I found the strange behavior of `ObjectSpace.each_object`. It misses some objects after `Ractor.new`. ``` $ ruby -ve 'class Foo; end; foo = Foo.new; Ractor.new do buz = Foo.new end.take; bar = Foo.new; p [ObjectSpace.each_object(Foo).to_a, foo.class, bar.class]' ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux] -e:1: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues. [[], Foo, Foo] ``` Of course it works well without `Ractor.new`. ``` $ ruby -ve 'class Foo; end; foo = Foo.new; bar = Foo.new; p [ObjectSpace.each_object(Foo).to_a, foo.class, bar.class]' ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux] [[#<Foo:0x00007fa84f4b26d0>, #<Foo:0x00007fa84f4b27c0>], Foo, Foo] ``` -- https://bugs.ruby-lang.org/
participants (3)
-
luke-gru (Luke Gruber)
-
nobu (Nobuyoshi Nakada)
-
wanabe (_ wanabe)