2

I've been trying to debug a phoenix application.
To do so I used the following instructions:
- To set a break point: require IEx; IEx.pry
- To start a debugging server: iex -S mix phx.server

The problem comes when starting the server, the above instruction leads me to the elixir interactive shell (iex(1)>) and does not allow the server to run, from here if I execute the code manually it stops in the prys but I was hopping to have the server running and stop whenever a request hit the pry. Is there any solution?

I am currently using earlang 1.20, elixir 1.5 and phoenix 1.3

  • Where did you add `IEx.pry`? – Dogbert Jan 30 '18 at 16:14
  • I placed the IEX.pry inside a function in a controller – Nicolás Pascual Jan 30 '18 at 16:16
  • `iex -S mix phx.server` should drop you into an iex session but should also start the server at port 4000 (or whatever you have it configured). You can't open localhost:4000 after running that? – Dogbert Jan 30 '18 at 16:28
  • That's exactly the issue, after running iex -S mix phx.server localhost:4000 does not open @Dogbert – Nicolás Pascual Jan 30 '18 at 17:57
  • 1
    Where exactly did you put IEx.pry? Are you sure you are not opening the page routed to the action with breakpoint? Also, check if you have another tab/browser opened with localhost:4000, maybe something else is opening the page and causing break. – Grych Jan 30 '18 at 20:47

1 Answers1

1

It is common behavior that the iex -S mix phx.server command opens an IEx shell. It runs the web server on the port configured for the Phoenix endpoint within the respective MIX_ENV simultaneously to that. For each IEx.pry() breakpoint it executes, it should prompt on the command line whether you want to open an IEx shell there.

Check which MIX_ENV your server is running in, e.g. by typing the following in the IEx shell:

Mix.env

And then find the configuration in the files within the config/ directory. The line should look like this:

config :nameofyourapp, Web.Endpoint,
  http: [port: 4000],

Maybe something other than 4000 is configured there? Or maybe some other application, or even a previously started instance of your web application already listens on that port and therefore prohibits the debug server from binding on that port? In that case, shutdown other running mix phx.server processes.

aef
  • 4,498
  • 7
  • 26
  • 44