From: "fxn (Xavier Noria) via ruby-core" Date: 2024-01-29T15:56:42+00:00 Subject: [ruby-core:116478] [Ruby master Bug#20188] `Module#const_source_location` returns wrong information when real constant was defined but autoload is still ongoing Issue #20188 has been updated by fxn (Xavier Noria). To me, this is related with `autoload`, because it is the `autoload` the one making the fibers deadlock. If the last line was ```ruby Fiber.new { p 1 }.resume ``` instead of a reference to the constant being autoloaded, there would be no deadlock, right? Same with `require`, if we try this without autoloads: ```ruby File.write('/tmp/bar.rb', <<~RUBY) Fiber.yield RUBY Fiber.new { require '/tmp/bar.rb' }.resume Fiber.new { require '/tmp/bar.rb' }.resume ``` we get a deadlock. So that is my point, what we say about threads does not translate to fibers. In fibers, you can deadlock. `Kernel#require` is thread-safe, things that would typically trigger a context switch (like I/O or `sleep`) won't make you deadlock if the other threads are waiting for that `require`. And same for `autoload`. And makes sense, because Ruby owns the thread schedulur mod hints API. > fibers being cooperative That is less the case with fiber schedulers, no? Can Falcon trigger deadlocks? ---------------------------------------- Bug #20188: `Module#const_source_location` returns wrong information when real constant was defined but autoload is still ongoing https://bugs.ruby-lang.org/issues/20188#change-106502 * Author: byroot (Jean Boussier) * Status: Open * Priority: Normal * ruby -v: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- Ref: https://github.com/fxn/zeitwerk/issues/281 `const_source_location` keeps returning the location of the `autoload` call, even after the real constant was defined. It only starts returning the real constant location once the autoload was fully completed. ```ruby # /tmp/autoload.rb File.write("/tmp/const.rb", <<~RUBY) module Const LOCATION = Object.const_source_location(:Const) end RUBY autoload :Const, "/tmp/const" p Const::LOCATION ``` Expected Output: ```ruby ["/tmp/const.rb", 1] ``` Actual Output: ```ruby ["/tmp/autoload.rb", 8] ``` Potential patch: https://github.com/ruby/ruby/pull/9549 -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/