Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange error in Phoenix logs: running MyApp.Endpoint terminated

I am getting following error in the phoenix webapp, I am developing. This is a simple app with few models and a page, where all models create form is added in a multi-tabbed form.

I am getting following error in the logs, However at browser's end things are working fine. From the logs also I am not able to understand what is wrong and how to debug this.

[error] #PID<0.1603.0> running MyApp.Endpoint terminated
Server: localhost:4000 (http)
Request: GET /
** (exit) an exception was raised:
    ** (Plug.Conn.AlreadySentError) the response was already sent
        (plug) lib/plug/conn.ex:428: Plug.Conn.resp/3
        (plug) lib/plug/conn.ex:415: Plug.Conn.send_resp/3
        (my_app) web/controllers/personal_info_controller.ex:1: MyApp.PersonalInfoController.phoenix_controller_pipeline/2
        (my_app) lib/phoenix/router.ex:265: MyApp.Router.dispatch/2
        (my_app) web/router.ex:1: MyApp.Router.do_call/2
        (my_app) lib/my_app/endpoint.ex:1: MyApp.Endpoint.phoenix_pipeline/1
        (my_app) lib/plug/debugger.ex:90: MyApp.Endpoint."call (overridable 3)"/2
        (my_app) lib/phoenix/endpoint/render_errors.ex:34: MyApp.Endpoint.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
        (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
like image 378
Saurabh Avatar asked Sep 26 '15 06:09

Saurabh


1 Answers

You get this error when you duplicate a response - this often happens when you have a plug that will send a response on some error (a user not being logged in for example) and then another response being sent from your controller action.

Without seeing your code it is hard to tell you where the problem is. After sending a response you can use Plug.Conn.halt/1 to prevent this error.

e.g.

conn
|> send_resp(404, "Post not found")
|> halt
like image 96
Gazler Avatar answered Nov 15 '22 15:11

Gazler