meh / cauldron

I wonder what kind of Elixir is boiling in there.
74 stars 7 forks source link

Example doesn't start an HTTP server #6

Open notduncansmith opened 9 years ago

notduncansmith commented 9 years ago

Forgive me if I'm just being dense, fairly new to Elixir.

Given the following module:

defmodule Bubble do
  use Cauldron

  # respond to a GET / request with "Hello, World!"
  def handle("GET", %URI{path: "/"}, req) do
    req |> Request.reply(200, "Hello, World!")
  end
end

IO.puts "Foo"
# open the cauldron on port 8080
Cauldron.start Bubble, port: 8080

Running mix run produces the following in the console:

Foo
Compiled lib/bubble.ex
Generated bubble.app

but doesn't actually start a server. What am I doing wrong?

notduncansmith commented 9 years ago

Oops, looks like I was being dense. So, removing that Cauldron.start line from the code, followed by entering it into the app console (iex -S mix) looked like it actually started the server. However, I now get the following error message after trying to hit http://localhost:8080:

00:24:50.488 [error] Error in process <0.218.0> with exit value: {#
{'__exception__'=>true,'__struct__'=>'Elixir.Socket.Error',message=><<16 bytes>>},
[{'Elixir.Socket.Stream','recv!',1,[{file,"lib/socket/stream.ex"},{line,63}]},{'Elixir.Cauldron.HTTP',headers,2,
[{file,"lib/cauldron/http.ex"},{line,74}]},{'Elixir.Cauldron.HTTP'...
essenciary commented 9 years ago

Me too, getting the same error (and is also affecting Urna) 20:43:03.661 [error] Error in process <0.238.0> with exit value: {#{'__exception__'=>true,'__struct__'=>'Elixir.Socket.Error',message=><<16 bytes>>},[{'Elixir.Socket.Stream','recv!',1,[{file,"lib/socket/stream.ex"},{line,63}]},{'Elixir.Cauldron.HTTP',headers,2,[{file,"lib/cauldron/http.ex"},{line,74}]},{'Elixir.Cauldron.HTTP'...

michaelowens commented 9 years ago

I seem to be having the same issue.

11:55:46.279 [error] Error in process <0.241.0> with exit value: {#
{'__exception__'=>true,'__struct__'=>'Elixir.Socket.Error',message=><<16 bytes>>},
[{'Elixir.Socket.Stream','recv!',1,[{file,"lib/socket/stream.ex"},{line,63}]},{'Elixir.Cauldron.HTTP',headers,2,
[{file,"lib/cauldron/http.ex"},{line,74}]},{'Elixir.Cauldron.HTTP'...

After messing around a bit further I noticed I was on a slightly older Elixir version (1.0.4 instead of 1.0.5). After updating the error has changed into:

12:22:38.754 [error] Process #PID<0.234.0> raised an exception
** (Socket.Error) message too long
    (socket) lib/socket/stream.ex:63: Socket.Stream.recv!/1
    (cauldron) lib/cauldron/http.ex:74: Cauldron.HTTP.headers/2
    (cauldron) lib/cauldron/http.ex:70: Cauldron.HTTP.headers/1
    (cauldron) lib/cauldron/http.ex:34: Cauldron.HTTP.run/3

I tried doing a request in Safari, and to my surprise it worked. For some reason it doesn't work when I try to visit from Chrome, but it does work from Safari. Sadly I can't use it this way, because other people who do requests to this server might have the same issue...

michaelowens commented 9 years ago

I did some more debugging and found out what the problem was for me. It was caused by cookies.

My localhost already had cookies on it from other projects, so I tried removing those and it served it correctly. I tried making some more cookies and after a while it crashes when there's too many/too much content in them. Limit seems to be around 1500-1600?

At least I know where the problem is now and I know it's not all that bad, but I do wonder if it would be possible to fix this (would it be an issue for the socket dependency?).