Phoenix saying config has changed when it hasn't (and causing shutdown)

I’m very new to Phoenix, so, apologies if this is badly phrased / something obvious! I have tried reproducing this on a test app and cannot, so, it probably is something unique to our codebase. With that said, it’s strange and quite reproducible!

What’s happening is this: In my config/dev.exs I create a config var from a System call (I can’t reproduce the issue unless I set the env):

config :my_app, wibble: !!System.get_env("FOO")

Then I start the app with FOO=BAR iex -S mix phx.server

Then I update some template file and phoenix stops with:

You must restart your server after changing the following files:

  * config/dev.local.exs

Note, I was editing something in lib/app/…something.html.heex … nothing which would normally cause a reload.

I tried to add some debug statements, eventually digging into the phoenix/code_reloader/server.ex and adding some dbg around the extract_stale code.

I poked around the stat values, and I got this zero value for the manifest:

|> #=> [0]

My assumption is that for some reason the compile.elixir is being written to while it’s being read (or something) and that’s why it’s getting a zero value and therefore thinking everything is out of date.

Does any of this make sense? Is there some obvious fix? Can anyone explain why this would happen at all, and seemingly only when there’s an ENV var set?

Sorry for not being able to write more clearly, like I said, very new to this (wonderful) ecosystem!

I’m running on OSX if that makes a difference.

Are you sure the phx.server process is the only one compiling your sources? E.g. try another (more dump) editor to see if the issue persists.

I’d be pretty sure some other process is compiling the sources. We do use Oban, so, maybe that would do it?

Can you explain what you mean by “try another (more dump) editor” ? I guess I could use some kind of :sys call perhaps find out what process is causing the compilation.

Are you trying to use the :wibble config at compile time (especially via Application.compile_env)? Mix keeps track of what the env vars were at compilation time and warns you if they are different at runtime.

There was only one instance of compile_env in the app. I removed it just to see if it would make a difference and no joy there.

Is it “normal” to have multiple processes looking for recompilation? I do have fswatch running, and I can see that any time there’s a recompilation that it seems to be being notified twice.

I would not call it normal, but I don’t use popular “advanced” IDEs like VSCode, which can do all sorts of things in the background. It probably is normal for those who use those tools. I suspect the “dump editor” comment was a typo for “dumb editor”. If you edit the file in something other than your main IDE, does the problem persist?

Another possibility is that perhaps you have some extra LanguageServer process running in the background that shouldn’t be. If you’re comfortable with Activity Monitor, you can search for beam processes in there and kill any stray ones, or try a reboot.

This seems like the first thing to straighten out.

How is dev.local.exs used?

I should be more clear.

The file name you say you have this env var in is different to the file name referenced by the error message.

1 Like

OK that was interesting. I am using vim (with an LSP). When I started it with vim -u NONE (to turn off all LSP integrations) then the problem goes away.

Many thanks for the suggestion @gregvaughn … now I’ll have to think about what to do about it!

ok - looks like this is almost certainly the issue → Live reload breaks debugging session in elixirLS debugger · Issue #133 · phoenixframework/phoenix_live_reload · GitHub


Actually probably not, this is being run in a debugger, which I’m not doing.