8
votes

I was following this guide for embedding Ejabberd into a Phoenix application (https://blog.process-one.net/embedding-ejabberd-into-an-elixir-phoenix-web-application/) and I'm having an error now that it' running.

Basically, everything appears to work fine until I navigate to "http://localhost:4000/ejabberd" at which point I get the following error:

[error] #PID<0.721.0> running EjbrdTest.Endpoint terminated Server: localhost:4000 (http) Request: GET /ejabberd ** (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 (ejbrdTest) web/controllers/ejabberd_controller.ex:1: EjbrdTest.EjabberdController.phoenix_controller_pipeline/2 (ejbrdTest) lib/phoenix/router.ex:265: EjbrdTest.Router.dispatch/2 (ejbrdTest) web/router.ex:1: EjbrdTest.Router.do_call/2 (ejbrdTest) lib/ejbrdTest/endpoint.ex:1: EjbrdTest.Endpoint.phoenix_pipeline/1 (ejbrdTest) lib/plug/debugger.ex:90: EjbrdTest.Endpoint."call (overridable 3)"/2 (ejbrdTest) lib/phoenix/endpoint/render_errors.ex:34: EjbrdTest.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

And rather than a list of users, I see this in the jumbotron:

Online users: < %= for user <- @users do %> < %= user %>

< % end %>

I've not been able to find anything on this, any ideas?

Thanks. Let me know if you need any more info.

3

3 Answers

13
votes

Removing plug :action will fix the issue. Looks like it is called by default now, so that line causes a duplicate error:

https://github.com/phoenixframework/phoenix/issues/888

1
votes

The blog post had a rendering issue (now fixed). There is no space between < and %.

You can download the actual source code from Gist: https://gist.github.com/mremond/383666d563025e86adfe#file-index-html-eex

1
votes

In my case, I was piping through an authentication function in my router. That auth function was returning a response but wasn't halting. Once I added a |> halt() to the end of the conn chain, I was good to go.

Just wanted to leave this hear in case I or someone else needs a quick reminder.