Tricote

Tricote

Hi all,

I’m seeing some unexpected recompilation behavior in dev, and I’m not sure what’s causing it.

Here’s the flow:

  • rm -rf _build deps .elixir_ls
  • mix deps.get
  • mix clean and mix compile
  • I start my Phoenix app with MIX_DEBUG=1 iex -S mix phx.server.
  • Everything boots up cleanly (already compiled).
  • I haven’t modified any .ex files.
  • Then, as soon as I make a request in the browser, a recompilation is triggered:

Shortly after that, a background process (in my case, an Oban plugin) crashes with an UndefinedFunctionError, because the module it depends on (like MyApp.Repo) seems to have been purged and recompiled after app startup.

Here is the output from iex just after the browser request:

    iex()>
    -> Running mix compile.elixir --purge-consolidation-path-if-stale /home/xxxxxxxx/workspace/my_app/_build/dev/lib/my_app/consolidated --no-all-warnings (inside MyApp.MixProject)
    ...
    [error] GenServer {Oban.Registry, {Oban, Oban.Sonar}} terminating
** (UndefinedFunctionError) function MyApp.Repo.query/3 is undefined (module MyApp.Repo is not available
    # ... (more similar errors)
    [notice] Application oban_met exited: shutdown
    # .... (errors)
    Compiling 432 files (.ex)
    # .... (still errors)
    <- Ran mix compile.elixir in 18412ms
    -> Running mix compile.app --purge-consolidation-path-if-stale /home/xxxxxxxx/workspace/my_app/_build/dev/lib/my_app/consolidated --no-all-warnings (inside MyApp.MixProject)
    Generated my_app app
    <- Ran mix compile.app in 6ms
    -> Running mix compile.protocols (inside MyApp.MixProject)
    <- Ran mix compile.protocols in 32ms
    [info] GET /patient/patient_records/new
    # ...
    [notice] Application my_app exited: shutdown
    iex()>

Things I’ve already tried:

  • Disabled all watchers in config/dev.exs (same behaviour)
  • Verified that I’m not touching any files manually.
  • Confirmed that it only recompiles after an HTTP request, not on app boot.
  • If I disable CodeReloader, I don’t have the recompilation…
config :my_app, MyAppWeb.Endpoint,
  code_reloader: false

So it seems like Phoenix.CodeReloader is the one triggering the recompilation but why would Phoenix.CodeReloader trigger a recompilation if no source files changed?

I have also the standard config for live_reload Endpoint

# Watch static and templates for browser reloading.
config :my_app, MyAppWeb.Endpoint,
  live_reload: [
    patterns: [
      ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
      ~r"priv/gettext/.*(po)$",
      ~r"lib/my_app_web/(controllers|live|components)/.*(ex|heex)$"
    ]
  ]

Also note that this happened after an update to erlang 28.0.2, elixir 1.18.4 from elixir 1.17 / erlang 27.

Any insights appreciated!

Thanks :folded_hands:

Showing Posts 1 to 10

dimitarvp

dimitarvp

Have you tried the usual suspects i.e. rm -rf _build deps .elixir_ls && mix do deps.get, compile?

Tricote

Tricote OP

Yes I already did that first, I forgot to mention it

Tricote

Tricote OP

I rolled back to erlang 27.0.1 and elixir 1.17.2 (without touching anything else), I get the following result (same flow, i.e. after cleaning _build deps folder and and clean recompile)

MIX_DEBUG=1 iex -S mix phx.server

The app starts as normal.
I start a browser request.

iex>
-> Running mix compile.elixir --purge-consolidation-path-if-stale /home/xxx/workspace/my_app/_build/dev/lib/my_app/consolidated --no-all-warnings (inside MyApp.MixProject)
<- Ran mix compile.elixir in 32ms
-> Running mix compile.app --purge-consolidation-path-if-stale /home/xxx/workspace/my_app/_build/dev/lib/my_app/consolidated --no-all-warnings (inside MyApp.MixProject)
<- Ran mix compile.app in 2ms
[info] GET /fr

# debug logs for the request

[info] Sent 200 in 41ms
-> Running mix compile.elixir --purge-consolidation-path-if-stale /home/xxx/workspace/my_app/_build/dev/lib/my_app/consolidated --no-all-warnings (inside MyApp.MixProject)
<- Ran mix compile.elixir in 32ms
-> Running mix compile.app --purge-consolidation-path-if-stale /home/xxx/workspace/my_app/_build/dev/lib/my_app/consolidated --no-all-warnings (inside MyApp.MixProject)
<- Ran mix compile.app in 2ms

I also get have a first mix compile.elixir --purge-consolidation-path-if-stale ... and a Running mix compile.app --purge-consolidation-path-if-stale but it doesn’t seem to do anything (I guess as it should since nothing changed…)

So it seems to work as expected. At least the request finishes successfully.

Strangely (?), after the request is returned, I see again those 2 calls in the logs… not sure it’s expected.

Tricote

Tricote OP

Note: I’ve tested the behaviour on a another app I have (elixir 1.18), and it seems normal to have the 2 mix compile.elixir --purge-consolidation-path-if-stale and mix compile.app --purge-consolidation-path-if-stale before the request and after…

But there is definitely something in my app that triggers the full recompilation in mix compile.elixir --purge-consolidation-path-if-stale

axelson

axelson

Scenic Core Team

Are you able to reproduce this in a sample project?

Tricote

Tricote OP

Yes I managed to have a test app with the error: https://github.com/novaccess-care/test_app

Basically I created a new app on the same elixir / erlang version (erlang 28.0.2, elixir 1.18.4), copied my app mix & mix.lock files, and my config.exs / dev.exs (removing a few things). I added a fake Oban job also to view the errors in the dev logs.

The tricky things is that it’s not consistent, the error may not appear sometimes… but it’s still pretty frequent, I would say one out of three times.

Basically I do this in loop to reproduce

MIX_DEBUG=1 iex -S mix phx.server

→ Wait for app to start
→ Go to http://localhost:4000/

If no error : Ctrl C + Ctrl C and do it again :

MIX_DEBUG=1 iex -S mix phx.server

→ Wait for app to start
→ Go to http://localhost:4000/

…etc

Tricote

Tricote OP

Youhou I found the culprit!

I removed one by one each of my dependency, and it turns out that it was related to Kino. It was probably not a good idea to include it in my dev environment, but at the time I thought it was convenient in order to have Kino in attached livebooks…

So removing this line from my mix.exs file solved the issue:

 {:kino, "~> 0.16", only: :dev},

I don’t understand why exactly it breaks my env like this though…

axelson

axelson

Scenic Core Team

Ah, I think it’s related to this _mix_recompile__? definition within Kino. What is that assets_path pointing to in your environment?

https://github.com/livebook-dev/kino/blob/cb7dceb36caeee626707eebb738c78d1fbf9ff53/lib/kino/js.ex#L392

vkryukov

vkryukov

Thanks a lot - I was hitting exactly the same issue: an upgrade from Erlang 27.3.4.1 to 28.1, with nothing else changed, was crashing Oban like in your case, and it was also fixed by removing kino from the dependencies.

Should we file a bug somewhere (kino project)? Or is this somehow expected?

steffend

steffend

Phoenix Core Team

Probably something for @jonatanklosko to look into! :slight_smile:

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
thiagogsr
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews