LoginSignup
7
7

More than 5 years have passed since last update.

マルチスレッドで、Circular dependency detected...

Posted at

マルチスレッドで自作のライブラリを追加する為に、autoloadを使用している場合に以下が発生する。

RuntimeError: Circular dependency detected while autoloading constant Lib::Hoge

autoloadはスレッドセーフでない為、衝突して発生する。

config/application.rb
config.autoload_paths += %W(#{config.root}/lib)

を使わずに

config/application.rb
config.eager_load_paths += %W(#{config.root}/lib)

で、以下の設定がされていること

config/environments/production.rb
config.eager_load = true

で改善される。

autoloadは、const_missing時に名前空間を元にファイルを読み込む。
eagerloadは、起動時にファイルを読み込む。
ちなみに、config.eager_load_pathsに設定したディレクトリは再帰的に読み込まれる。

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7