8

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.

Mickaël Rémond
  • 9,035
  • 1
  • 24
  • 44
Nodal
  • 353
  • 2
  • 14

3 Answers3

13

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

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Everhusk
  • 131
  • 1
  • 3
  • Thanks, that helped in my case! – jhlllnd Feb 25 '16 at 11:42
  • Thanks for the response! I haven't used Elixir in several months now, but I may just dig it up again and try this out. Hoping the documentation hoard got a bit more mature while I've been away. – Nodal Apr 22 '16 at 07:50
1

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

Mickaël Rémond
  • 9,035
  • 1
  • 24
  • 44
  • Unfortunately, that didn't help. My exact source for ejabberd.html.eex:

    Hello World, ejabberd meets Phoenix !

    Here is the list of online users:

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

    <%= user %>

    <% end %>
    – Nodal Sep 08 '15 at 07:27
  • You should restart from scratch the tutorial using the source code in the gist. There is more code than just this file. – Mickaël Rémond Sep 08 '15 at 07:33
  • Thanks, I'll give it a shot but I've already restarted several times and also tried using the code from gist... I'm very confused :P – Nodal Sep 08 '15 at 07:41
  • Right, well, now that has corrected the issue I never knew about (not displaying properly as you showed above), but the bigger issue of that "the response was already sent" error remains at large. Ever seen this before? Thanks again. – Nodal Sep 08 '15 at 08:01
  • Well, it really mean that the response was already sent and possibly returned in another module in the routing pipeline. You may see more information on this error on this page: http://blog.gazler.com/blog/2015/07/18/subdomains-with-phoenix/ – Mickaël Rémond Sep 08 '15 at 08:14
  • Unfortunately, the only reference to that error there bears no relation ot my code as I am not using subdomains on only have one thing called PageController (or EjabberdController for that matter, if there was another where would it be...). I found that link earlier, but haven't found a huge amount else. Any further help would be much appreciated (I'm kind of new in case you hadn't guessed). – Nodal Sep 08 '15 at 08:31
  • It is hard to say more without seeing your whole code. I think your original error was simply a syntax error in your code that got the routing process confused. – Mickaël Rémond Sep 08 '15 at 08:33
  • Thanks, got it. I've rewritten this whole thing several times over now though and have no idea where to look for something like that any more. The same error has persisted each time and is still there now, completely unchanged. Thanks for the help. If you have any further ideas, or even hints as to where to look, let me know. – Nodal Sep 08 '15 at 08:38
  • Did you follow the tutorial step by step with exact same code ? – Mickaël Rémond Sep 08 '15 at 09:03
  • Initially no. But in this version? I believe so, yes (with the exception of Phoenix having added a few more dependencies and such - newer version or something I guess). – Nodal Sep 08 '15 at 09:09
  • When I have a moment I will try with latest version of Phoenix then, to see if this change anything. You could also try with older version to see if this is working. – Mickaël Rémond Sep 08 '15 at 09:47
  • Thanks, I'll get on that. Let me know how it goes on your end. – Nodal Sep 09 '15 at 03:32
  • Hey, any changes on your end? I tried using an older version which did seem to work, however that's not an ideal solution. Also, commenting out "plug :action" in the ejabberd controller did remove this error, however I can't test if that really helped because I now (with or without that plug definition) get an error saying ejabberd_auth doesn't exist when I try to add a new user from the command line (possbily related to dependency problems - terrible internet in Beijing lately, downloads keep messing up). – Nodal Sep 15 '15 at 05:53
  • No, we did not change anything yet. I did not had time to try with latest Phoenix version. – Mickaël Rémond Sep 15 '15 at 06:45
1

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.

Mario Olivio Flores
  • 2,395
  • 1
  • 20
  • 19