Compiler Deadlock (but only on compiling changed files)

Tags: #<Tag:0x00007f11426a1c88> #<Tag:0x00007f11426a1a80>


Hello all,

I have an issue that I’ve been unable to reproduce on a smaller scale. For certain files, when I change them and run mix compile, I get a compiler deadlock on a circular dependency. This is after introducing behavior to dynamically generate ecto associations. We do this because we will often use views that are sourced from the same table (so they relate in the same way) but contain different data and derive different data. So in our schema we would say something like:

schema "posts" do
  field :title, :string
  field :content, :string

  Comment.Versions.for_all_versions(fn version_name, version_schema -> 
    has_many version_name, version_schema, foreign_key: :post_id

Does anyone know of anything that might cause this behavior? To me, getting a deadlock on a file change but not when running a mix compile --force implies that some module somewhere doesn’t know about a dependency it has.



You might need to require OtherModules in your module to induce a compile-time dependency.

Do note, circular dependencies break pretty easily so you may need to lift a dependency into a remote call and ‘ensure’ another file is compiled first, having it handle the case where the first is not compiled yet.

Better to take the circular parts out into another module. ^.^


Yeah, I ended up solving this by making a registry that contains the mapping of modules to versions and builds the relevant data w/o actually calling into other modules, and then I added after compilation checks to ensure that each module was appropriately configured in that registry (something that is awesomely easy to do in elixir).