Issues with running Phoenix 1.4 app

Hi guys,

I’m having some weird problems with running a Phoenix 1.4 app. I have never seen this before with Phoenix 1.3. Right after the app is built afresh I can start it with mix phx.server just fine. Then I do Ctrl-C + Ctrl-C to exit, and upon restart I will most likely get this:

 → mix phx.server
Compiling 24 files (.ex)
[info] Running MasterCoachWeb.Endpoint with cowboy 2.5.0 at http://localhost:4000

Webpack is watching the files…

[error] Ranch listener MasterCoachWeb.Endpoint.HTTP had connection process started with :cowboy_clear:start_link/4 at #PID<0.543.0> exit with reason: {:undef, [{:cowboy_http, :init, [#PID<0.440.0>, MasterCoachWeb.Endpoint.HTTP, #Port<0.44>, :ranch_tcp, %{env: %{dispatch: [{:_, [], [{:_, [], Phoenix.Endpoint.Cowboy2Handler, {MasterCoachWeb.Endpoint, []}}]}]}, stream_handlers: [Plug.Cowboy.Stream]}], []}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}

[error] Ranch listener MasterCoachWeb.Endpoint.HTTP had connection process started with :cowboy_clear:start_link/4 at #PID<0.544.0> exit with reason: {:undef, [{:cowboy_http, :init, [#PID<0.440.0>, MasterCoachWeb.Endpoint.HTTP, #Port<0.45>, :ranch_tcp, %{env: %{dispatch: [{:_, [], [{:_, [], Phoenix.Endpoint.Cowboy2Handler, {MasterCoachWeb.Endpoint, []}}]}]}, stream_handlers: [Plug.Cowboy.Stream]}], []}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}

[error] Ranch listener MasterCoachWeb.Endpoint.HTTP had connection process started with :cowboy_clear:start_link/4 at #PID<0.545.0> exit with reason: {:undef, [{:cowboy_http, :init, [#PID<0.440.0>, MasterCoachWeb.Endpoint.HTTP, #Port<0.46>, :ranch_tcp, %{env: %{dispatch: [{:_, [], [{:_, [], Phoenix.Endpoint.Cowboy2Handler, {MasterCoachWeb.Endpoint, []}}]}]}, stream_handlers: [Plug.Cowboy.Stream]}], []}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}

By trial and error, I found that it’s enough to remove compiled version of cowboy with $ rm -rf _build/dev/lib/cowboy to have another mix phx.server run the app successfully, but then on the next run I have to remove it again.

Any idea what this may be?

2 Likes

I narrowed it down a bit. It happens only when my code base recompiles. If I exit the app and then start again, nothing bad happens. If I change some code, exit and re-run, it mentions compiling some code as above and then starts dumping errors.

1 Like

Do you have any concurrent compilations happening, like say do you have an IDE or Editor open that recompiles on save too? If so then change your IDE/Editor to the MIX_ENV=test environment or something.

Nope, nothing like it. Only webpack that is usually doing it’s magic on launch and live reload that recompiles sources on change. What do you think?

Hi,
which Plug do you use? I think we had similar issue when we used old plugs deps.

plug 1.7.1
plug_cowboy 2.0.0

I think I’m getting another observation. If I remove ANY (not just cowboy as I stated above) compiled dependency from _build folder prior to running mix phx.server, it obviously triggers compilation of that lib and then the app. After this it all starts nicely.

Started out with 1.4 and I am also experiencing this in my brand new installation.

I actually progressed quite a bit with my research and figured that it’s beam.smp process killing my .beam files of certain packages. Not all. I used dtrace tool to trace the removal of .beam files.

I’m looking for the reasons at the moment.

@chu are you using Vim by any chance?

Yes I am using Vim.

And ale plugin for Vim?

Yes I have that too

I just discovered that it triggers recompilation that ruins beam files for certain dependencies that in turn ruins the app and it won’t launch the next time with full deps recompilation.

Note that disabling this specific “elixir” linter won’t work. It still does this recompilation. Disabling whole ale plugin worked for me.

Give it a try and let me know.

2 Likes

Has this be solved?

I had the same issue just now, and I updated Plug and Plug_Cowboy to the newest 1.7.1 and 2.0.1, issue still there.

And I found my code is the reason:
I return conn more than one time, something like the following:

def somefunc(conn, ...) do
  case xxxx do
    xx ->
      render(conn, ....)
   yy ->
     render(conn, ... )
  end
  render(conn, ...)
end

Then I removed last render expression, it solved.

Hope it help.

2 Likes

Your code does return conn only a single time, and it’s always the last one, it does render up to two times though, depending on the matches in the case.

3 Likes

It’s not the issue for the case I described. One post above yours I explained what happened. Not using ALE plugin from now on as it triggers recompilation in the background that somehow removes beam files.